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
Related
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
Now I'm supporting multiple resolution with multiple layout folders.
I'm using android development studio and I made 3 different folders.
layout
layout-large-port-1280x720
layout-normal-port-800x480
and I tested on 800x480 and 1280x720. 480x800 worked well, but 1280x720 follow 800x480 folder's dp and UI.
I don't know why this thing happens to me and I don't know how to solve the problem.
Why it doesn't work and what should I have to do?
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.
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
Thats code in the Manifest supports all dpis.
<supports-screens android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true" />
make sure you have given the corresponding drawables in drawable-xhdpi
I don't know on what basis you're creating the App. But it's better to avoid creating layout for specific screen sizes.. Instead you would give the following:
layout-small-port for devices like samsung galaxy y
layout-normal-port for devices like galaxy s2
layout-large-port for devices like nexus 7 which is 7 inch
layout-xlarge-port for devices having more than 7 inch size
If you specify the screen size, you can't support more number of devices
U should use:
res/layout/main_activity.xml # For handsets (smaller than 480dp available width)
res/layout-sw480dp/main_activity.xml # For phones (480dp wide and bigger)
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/drawable – The default image folder
res/drawable-sw200dp
res/drawable-sw600dp
res/drawable-sw800dp
We would like to design layouts for specific resolutions as below:
Samsung Duos: 480 X 800 Android Version 4.0.4
HTC Velocity: 540 X 960
To do so we have created layout folders for each as below:
layout-w480dp-h800dp
layout-w540dp-h960dp
Assuming that if we run application on samsung duaos it should pick the layouts from
layout-w480dp-h800dp folder but it is giving error and unable to start activity.
The error is:
android.content.res.Resources$NotFoundException: Resource ID #0x7f030029
It means it could not locate the layout required by the activity. Same happen with HTC Velocity.
Are we doing something wrong?
Please let us know if you have any idea.
must have been a problem with some resource try to delete a image file from drawable and add it again build the project it should run
Did you try to Clean and Build? It usually help as looks like R generation was corrupted
Your assumption is wrong.
layout-w480dp-h800dp isn't for 480x800 px screen.
DP is way Different than PX. Please read this http://developer.android.com/guide/practices/screens_support.html.
Are you sure you really need different designs for so similar handsets? I would say this is pointless.
In my opinion at most U should distinguish 3 types of devices.
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 still want to do what you are trying to do you can try px instead of dp. But Im not sure if this will work ...
Do you have a default layout that relate to your activity?I mean each folder containing the layout of the same name.
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).