-1

I have read many things about supporting multiple devices. Right now I have implemented it in my application, I have made following folders as shown below :

  1. layout (default folder)
  2. layout-large
  3. layout-normal
  4. layout-small
  5. layout-xlarge
  6. layout-xxlarge

and declared this in the xml file

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

But its not working, my all devices are picking layout from the normal layout folder what should be the problem in here?

And also tell me what should I do for supporting the xxxhdpi devices?

ppreetikaa
  • 1,149
  • 2
  • 15
  • 22
Coas Mckey
  • 701
  • 1
  • 13
  • 39
  • your folder names are incorrect, should be such as res/layout-sw600dp ,please check other question , such as [that](http://stackoverflow.com/questions/9513910/how-to-give-layouts-folder-name-to-support-multiple-screen-size-in-android) – Alp Aug 10 '15 at 08:07
  • Can you update your question so we can see how is your res folder ? – Tsunaze Aug 10 '15 at 08:07
  • @Tsunaze these are as follows layout (default folder) layout-large layout-normal layout-small layout-xlarge layout-xxlarge – Coas Mckey Aug 10 '15 at 08:12
  • @CoasMckey see my updated answer – King of Masses Aug 10 '15 at 08:13
  • @alp but sw refers to tablets screen , I have read this some where – Coas Mckey Aug 10 '15 at 08:18
  • sw600dp means tablet (7 and 10 inch), but if you specify sw720dp, layout, 10 inch tablet will go and take layout from there. you can also specify for 480 and 320d. – Alp Aug 10 '15 at 10:19
  • @alp how about just supporting different screen sizes of handset devices I mean cell phones – Coas Mckey Aug 10 '15 at 10:26
  • res/layout-sw320dp-xhpi/ , res/layout-sw320dp-hdpi/ , res/layout-sw480dp-xdpi/ etc... (some phones are working in 480 some are in 320 or below) – Alp Aug 10 '15 at 10:36
  • where as I have read that the qualifier sw is used for the short width which indicates towards the tablet ,, ? – Coas Mckey Aug 10 '15 at 11:46
  • but you aare saying using this would work on cell phones ? are you sure ? – Coas Mckey Aug 10 '15 at 11:46

2 Answers2

2

According to the note written in this documentation Supporting Multiple Screens, the old groups was deprecated (small, normal, large, and xlarge), which is why we have to migrate to the new technique defined in Android 3.2.

Note: Beginning with Android 3.2 (API level 13), these size groups are deprecated in favor of a new technique for managing screen sizes based on the available screen width. If you're developing for Android 3.2 and greater, see Declaring Tablet Layouts for Android 3.2 for more information.

Old way classification :

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp

New way :New configuration qualifiers for screen size (introduced in Android 3.2).

320dp: a typical phone screen (240x320 ldpi, 320x480 mdpi, 480x800 hdpi, etc).
480dp: a tweener tablet like the Streak (480x800 mdpi).
600dp: a 7” tablet (600x1024 mdpi).
720dp: a 10” tablet (720x1280 mdpi, 800x1280 mdpi, etc).

res/layout-sw320dp/main_activity.xml # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)

Refer the Supporting Multiple Screens documentation for more support !!

So here also there will be a weird problem we have that to controlling the different mobile devices (not tablets) i.e we have devices like 3.5' 5', 5.5' and so on.

So to achieve the multiple mobile screen support (accurately) you can create different values folders in your app like below

enter image description here

Then declare all your dimension values in the dimens.xml file as your need , and use the values from the dimension file (it means not hard coded values in your xml files.. every value should be come from dimens file like @dimen/ ) For example in you home screen you have a left padding of 5dp and text size of 24sp and some other dimension values also.

So you need to create a dimens.xml file in your values folder like below.

<dimen name="button_height">120dp</dimen>
<dimen name="buttonTextSize">15dp</dimen>
<dimen name="button_margin">10dp</dimen>
<dimen name="buttonHeight_normal">37dp</dimen>
<dimen name="left_padding">5dp</dimen>

then you can use the same in your xml file like below

<Button
        android:id="@+id/rButton"
        android:layout_width="wrap_content"
        android:layout_height="@dimen/button_height"
        android:layout_marginTop="@dimen/button_margin" 
        android:textSize="@dimen/buttonTextSize"
        android:padding="@dimen/left_padding" />

in the same way you can create different dimens.xml files in different values folders and then you can create the same dimension names & change your required sp & dp values.. so that while loading the xml file it will take the dimension values from required values folder

This link may help you for more details

Community
  • 1
  • 1
King of Masses
  • 18,405
  • 4
  • 60
  • 77
  • i have read that document 1000 times almost and you can see in the section look at table one for layout , they are saying this Size small Resources for small size screens. normal Resources for normal size screens. (This is the baseline size.) large Resources for large size screens. xlarge Resources for extra-large size screens. – Coas Mckey Aug 10 '15 at 08:25
  • what you are saying is for tablets , please the link thoroughly in you answer – Coas Mckey Aug 10 '15 at 08:25
  • The way you are saying is deprecated from android 3.1. – King of Masses Aug 10 '15 at 08:27
  • then how to support different mobile screens not tablets? – Coas Mckey Aug 10 '15 at 08:40
  • by creating different dimensions folders you can support different mobile screens – King of Masses Aug 10 '15 at 08:49
  • please send me the link on how to making the different folders for the different screens of all mobile devices – Coas Mckey Aug 10 '15 at 08:51
  • i tried the same in my application it is working too. i am using different dimensions folders in my app – King of Masses Aug 10 '15 at 08:58
  • but I dont under stand , I have to make single layout and then how to give dimension in it , for example in main layout I have given the left padding as 3dp then How I can give that padding in the values folder and hwo to refer this – Coas Mckey Aug 10 '15 at 09:06
  • my answer was updated. still if you face the problem, refer the links. soon i vll be back to help you :) – King of Masses Aug 10 '15 at 09:22
0

The way you are using is deprecated from android 3.1. Read the MulitScreen Support

Your layout folder must be as this

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)

Read the document thoroughly.

Arun Shankar
  • 612
  • 1
  • 5
  • 16