Creating multi-screen support app android
Asked Answered
S

4

10

I am creating a app in Android that must support multiple screens.

For this purpose i have read many answers and one which i like most is state that i can create different folders in res folder by following name,

For small screens layout-small,

For large screens layout-large,

For extra large screens layout-xlarge

and i have to create different layouts for different screens with same name. e.g mylayout.xml

and i have to put following code in manifest.xml file

<supports-screens android:smallScreens="true" 
      android:normalScreens="true" 
      android:largeScreens="true"
      android:xlargeScreens="true"
      android:anyDensity="true" />

and finally i just need to write following lines in my Activity file,

  setContentView(R.layout.mylayout);

Now when i run this app in different size screens it should acquire layouts from different folders as per screen resolution.

But this is not happening in my case.It takes only layout that defined in layout folder.

Please can some one explains me why this happening and how can i solve this issue so that my app can run effectively on all size screens.

Scarberry answered 29/3, 2014 at 7:9 Comment(7)
You have to copy the xml file to those foldersDigestif
no i have created separate screens in each folderScarberry
if the screens are with same names? i.e. main.xml in each folderVasodilator
then plaese try name like this layout-sw320dp,layout-sw480dp,layout-sw600dp,layout-sw720dpDigestif
yes i have using same namesScarberry
@JayVyas check this android-developers.blogspot.in/2011/07/…Aleta
possible duplicate of multiple screen support in androidPromissory
D
17

Try out like:

  • layout-sw320dp
  • layout-sw480dp
  • layout-sw600dp
  • layout-sw720dp

instead of

  • layout-small,
  • layout-large etc...
Digestif answered 29/3, 2014 at 7:10 Comment(3)
btw what should i try for drawable images ?Scarberry
same way you can create try drawable-xxhdpi,drawable-sw-720dp etc. .Implosive
what if one folder supporting multiple screen ??Rockyrococo
S
8

Please refer below link:

http://developer.android.com/guide/practices/screens_support.html For Different screen size, The following is a list of resource directories in an application that provides different layout designs for different screen sizes and different bitmap drawables for small, medium, high, and extra high density screens. you could use different size of the layout files in res folder and also vary for drawable images based on the density..

  res/layout/my_layout.xml             // layout for normal screen size ("default")
  res/layout-small/my_layout.xml       // layout for small screen size
  res/layout-large/my_layout.xml       // layout for large screen size
  res/layout-xlarge/my_layout.xml      // layout for extra large screen size
  res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

enter image description here res/drawable-mdpi/my_icon.png // bitmap for medium density res/drawable-hdpi/my_icon.png // bitmap for high density res/drawable-xhdpi/my_icon.png // bitmap for extra high density

<compatible-screens>
    <screen
        android:screenDensity="ldpi"
        android:screenSize="small" />
    <screen
        android:screenDensity="mdpi"
        android:screenSize="normal" />
    <screen
        android:screenDensity="xhdpi"
        android:screenSize="large" />
    <screen
        android:screenDensity="xhdpi"
        android:screenSize="xlarge" />        
</compatible-screens>

And followed by any activity use this lines..

android:configChanges="orientation|screenSize|keyboardHidden"

Sigurd answered 29/3, 2014 at 7:30 Comment(2)
One thing to keep in mind is that many times a single layout xml will be fine, so you may only need just one layout folder. In that case you would still want different values folders for specific dimens / drawables / etc. Referencing those resources from the single layout makes life much easier.Lammastide
your approach is good but it's difficult to go through every folder and update the changes...Can we do through single folder like layout and layout-land for all the screensPow
C
4

In values folder naming convention like layout-small only works for devices with api version less than 3.1. You should create values file with naming like layout-sw600dp for api level greater than 3.1. read this http://developer.android.com/guide/practices/screens_support.html3.1api

enter image description here like this you should create layout-sw600dp, layout-sw720dp for each type of devices. layout-sw600dp means this layout works for devices with smallest width of 600dp If you have layout-600dp and layout-sw720dp folders. first layout folder works for devices with smallest width of 600dp(7 inch tablet) to 720dp and second works for devices with smallest width above 720dp(10 inch tablet).

If your minimum required version is above 3.1 you don't need have layout-small, layoutxLarge folders. otherwise you have to consider both type of layout fromats.

Chekhov answered 29/3, 2014 at 7:17 Comment(0)
I
1

Here is a quick checklist about how you can ensure that your application displays properly on different screens:

Use wrap_content, fill_parent, or dp units when specifying dimensions in an XML layout file. Do not use hard coded pixel values in your application code(.java files). Do not use AbsoluteLayout (it's deprecated in Android 1.5). You should instead use RelativeLayout, which uses relative positioning to lay out its child views. Supply alternative bitmap drawables for different screen densities.

Take time and read these screens_support or to get a better idea see How Android Finds the Best-matching Resource so that you know where to place your resources.

Ideally answered 22/1, 2015 at 9:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.