I would like to create different layouts for tablets and handsets in Android. Where should I put the layout resources in order to make this differentiation?
I know this is an old question, but for the sake of it...
According documentation, you should create mutiple asset folders like 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)
If you are using Fragment concept in the code(means Multi-Pane layout) then its best to use wdp instead of swdp
res/layout-w600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-w720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)
res/layout-w600dp-land/main_activity.xml # For 7” tablets in landscape (600dp wide and bigger)
res/layout-w720dp-land/main_activity.xml # For 10” tablets in landscape (720dp wide and bigger)
Refer the table for understanding wdp
Table 2. New configuration qualifers for screen size (introduced in Android 3.2).
In the following link
http://developer.android.com/guide/practices/screens_support.html
With layouts, I believe you can only current differentiate by the following:
res/layout/my_layout.xml // layout for normal screen size
res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-large-land/my_layout.xml // layout for large screen size in landscape mode
You can find more info on what you can add to the folder structure to differentiate between different settings here.
The biggest problem is that the Android SDK hasn't really incorporated tablets officially. Hopefully that will be resolved in the next version of Android. Otherwise, you just need to make sure you use scaling layouts that will work for any screen size.
According documentation, you should create mutiple asset folders like this..full list......
res/layout/main_activity.xml // For handsets (smaller than 600dp available width)
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)
res/layout-sw600dp-land/main_activity.xml // For 7” tablets in landscape (600dp wide and bigger)
res/layout-sw720dp-land/main_activity.xml // For 10” tablets in landscape (720dp wide and bigger)
"Orientation for preview" dropdown in Android Studio as shown below can help generate quick landscape and tablet layout xmls. It also creates separate folders i.e. layout-land and layout-sw600dp for these layout variations and place the layout xmls within these folders.
This source also providing how to call any resources based on device configurations, like: language, screen width/height, layout direction, screen orientation...etc.
You've to be careful to make a default resource as the source mentioned, like calling high quality of icons for tablets.
Related
When I create small,normal,large,xlarge layouts:How Android Detects Screen Size phone for use this layouts?base on dp or dpi or px?
Is the result always right?Because some devices are smaller in physical size but the density is higher so if based on density this detect is not always correct.
Am I right?
Android uses dp, but there are a lot of variants you can create in your resources for example
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)
You can cover more resolutions using different configs, but I think is hard work to cover everything, because how I said we have different resolutions, screen sizes and now we have notch.
res/layout-560dpi/
res/layout-ldpi/ ...
Bellow, I copy a link about this
https://developer.android.com/training/multiscreen/screensizes
I have a problem when I launch my Android app on an Acer 7 inches tablet (Android 6.0). Until changing the tablet orientation, the fontSize is bigger that it should be. I don't have this problem with other tablet.
At the end of an onCreateView, I get resources information with getResources().getConfiguration().fontScale. With a normal system fontSize, it return 1.15 when app is launched and return 1.0 when changing orientation and remain 1.0 after even if I changed orientation again and again. With normal size font on the other tablet fontScale is always 1.0.
I don't know where to look to solve this problem.
For font change for tablet UI you create the new layout for tab and set the text size according to the tab UI.
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
This is how my layout looks on the phone (landscape):
button wrapper (marginTop 10dp, margin left 5dp and 3 dp between buttons)
The problem is when I run the same layout on the tablet:
As you can see there is an extra space below the button wrapper.
Am I need to create different layout for each device display?
Yes you should create another layout for tablets. if the layout for the phone comes in tabs obviosly it will get smaller..youcan go through this oink about creating different layouts for different displays..Mainly for layouts will be provided for an app
layout-small ,
layout ,
layout-large ,
layout-xlarge,
Link
Iam not getting what your actual point is..but yes for tablets you need to make different xml layout files which are put under layout-large and layout-xlarge(depending upon your requirement) folders. And if you'r not doing so then your tablet will render the layout from your default layout folder.
Is this what you were asking ?
You can do with help of this
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 landscapeorientation
for drawable
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
I think you need 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)
http://developer.android.com/guide/practices/screens_support.html
I saw one android app my galaxy tab(1024*600), it has fixed resolution 800*480.
How to fix my app's resolution like 800*480?
my client wants to fix app resolution..
You can explicitly define your layout width and height in layout xmls to be 800*480 for all the un-supported resolutions like 1024x600.
A list of sample layout folders:
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
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
In case of 3.2 or later, you can define layout files for tablets as well:
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)
I don't recommend fix your width and height to a specific value but since it's client request, I guess you have to take it.
Or you could set target sdk version to 1.5 or 1.6. I haven't really tried it yet, but I read somewhere that doing so limits the application to be displayed in a lower resolution.
I am developing a game and want to support all screens which have 240dp density. These screens lies in hpdi-category of Android e.g. some tablets like 10.1" and 7.0", some phones which have 480*800 screens, etc. Can you please tell me how to provide alternative drawables.
Thanks in advance.
Just put the drawable files into the drawable-hdpi or drawable-mdpi folder respectively.
For full control depending on your needs you might want to check http://developer.android.com/guide/practices/screens_support.html
Here you find all the possibilities...
You may especially check the new size qualifiers. In particular (also from the link above):
For other cases in which you want to further customize your UI to differentiate between sizes such as 7” and 10” tablets, you can define additional smallest width layouts:
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)
Answering the next question, you can qualify for the whole range of options, from current locale to display width/height. See http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
You can use size or density qualifiers for your drawable folder. If you for example have a fullscreen background drawable for a tablet and for a phone you can create a drawable-xlarge folder. This folder will be used on a table only. You could also combine the ressource qualifiers like drawable-xlarge-hdpi. For more information on this read Providing Ressources.
I would suggest to specifiy your layout by screen size only. Resulting in four layout folders layout-small, layout-normal, layout-large, layout-xlarge. The normal drawables that only need a bigger resolution with a higher screen density like buttons or other stuff that is shown in the same size on phones and tablets should be put into the density dependent folders like (drawable-ldpi, drawable-mdpi, drawable-hdpi, drawable-xhdpi).