Configuration qualifers - Multiple screen size - android

I'm creating an application for smartphone tablet and televison.
I'm creating my different displays, but I can not differentiate the tablet from the television.
I read https://developer.android.com/guide/practices/screens_support.html
I have tried many things, large,xlarge sw720dp, W1024dp.. but nothings works. I work with the emulator.
AndroidTv 1080p API 25, Résolution 1920*1080:xhdpi
Nexus 5 API 24 Résolution 1080*1920:xxhdpi
Nexus 7 1200*1920 xhdpi
Thanks for your help !

The documentation you want is here: https://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
The important parts of this page are Table 2 (configuration qualifier names) and the section titled How Android Finds the Best-matching Resource.
Reading these, it is clear that you will use the Smallest width qualifier to differentiate between phone and tablet devices, and the UI mode to differentiate between televisions and non-televisions. This directory structure should work:
res/
layout/
layout.xml (default (i.e. phones))
layout-sw600dp/
layout.xml (non-televisions 600dp or wider (i.e. tablets))
layout-sw600dp-television/
layout.xml (televisions 600dp or wider)
Because the Smallest width qualifier has a higher precedence than the UI mode qualifier, if you tried to just use layout-television you would find that your TV still used the -sw600dp layout.

Related

how to customize and organise Layouts Folder(Size) properly?

I've tested my app in some devices with different sizes, and i've got terrible style at last. i've read some documents about folder layout and sizes for customizing layouts for different sizes of phone.
So base on what i've read i've added below lines into Manifest.
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens= "true"
android:anyDensity="true"
/>
and copied layout contents to other created folders which they are :
layout-large
layout-small
layout-xlarge
layout-xlarge-land
and started to edit one of them to see the result, and nothing happend and design was same, so i thought i could be designed wrong xml folder, so base on another tutorial i've added another folder with layout-sw320dp and it's worked but problem is now, everything is showing like 320dp folder, large and small doesn't matter. and in design view all folders are phones models sizes changed to :
Nexus One -> sw320dp\*.xml
Pixel -> sw320dp\*.xml
So what's the reason of this? and what are the sizes of these layout folders with small and large name exactly? and how i should make this layout work properly?
Looks like my folders are not actually related to exact sizes, 320 is overwriting on all sizes except wear android.
The swXXXdp resource modifier means that this folder will be selected if the device's "smallest width" is XXX dp or greater. So if you have these two directories:
res/layout/
res/layout-sw320dp/
Then any device that has a smallest width of 319dp or less will use the layout/ files, and any device that has a smallest width of 320dp or more will use the layout-sw320dp/ files. Almost every device is 320dp or more, so you'll see that almost every device uses this folder.
Modern phones tend to have around 400dp of smallest width. You can always look screen specs up online. For example, https://www.gsmarena.com/google_pixel_2-8733.php says that the Pixel 2 is 1080px wide at 441 pixels per inch; this works out to 391dp (1080 / (441/160)).
Common cutoffs for the swXXXdp modifiers are 600dp for seven-inch tablets and 720dp for ten-inch tablets. So you might want a project structure like this:
res/layout/ <-- everything smaller than a 7" tablet
res/layout-sw600dp/ <-- 7" tablets
res/layout-sw720dp/ <-- 10" tablets
Note, though, that you can use any number you want. sw503dp is totally valid. You'll just have to choose what numbers work well for your layouts.
As for layout-large and layout-small etc, just ignore those. Those are outdated, and were used before the swXXXdp qualifier was added. Unless you're developing for extremely old API versions, you're better off just using swXXXdp instead.
You're starting the layout name with capital letter Layout-large. Replace those letters with small case (e.g: layout-...) and it would work.

Android, different layout for 10.1 and 9.7 inch displays

I've developed an app for an specific 10.1 inch display (2560x1600) and my layout files are written to fit that specific resolution.
Now I need to make the same app to work with an 9.7 inch display (2048x1536).
It's the first time I have to do a thing like this and I don't know which is the right approach. Using the actual layout file in the new tablet is a bit of a mess, nothing fits correctly, is like making a zoom in the old one.
I've read a bit about creating folders for different layouts, but the problem is that if I create a folder "layout-sw720dp" both tablets use the same layout, which I don't want to.
Is the "different layout files" the right approach? If so, how can I specify a layout for an specific "resolution" or whatsoever?
Is there other way to approach this?
Thanks!
In Android, there are different types of attribute qualifiers which helps us to design the app for different types/resolutions of devices. However in this particular case here, both the resolutions would come under the same attributes for almost all the qualifier types.
They both would come under the xhdpi bracket for xlarge devices. So you cannot use these qualifiers. But the one thing that is not same will be the shortest width qualifier for the two resolutions.
The shortest width for 2560 x 1600 would be 800dp and shortest width for 2048 x 1536 would be 768dp. So you can use the layout-sw<>dp attribute to distinguish the two devices.
for 10.1 inch display (2560 x 1600) : layout-sw800dp
for 9.7 inch display (2048 x 1536) : layout-sw768dp
When you use the layout-sw720dp folder, both the devices will take the same folder as the shortest width of both devices are greater than 720. Check this developer doc section (especially the table) for more information.
In the app folder of your application in android studio , go to the res-> layout, right click on that select New -> Layout resource file. on the new resource file window ,give file name dimens.
on the available qualifiers select dimension and push it into the chosen qualifier and specify the dimension as 2048x1536. you can use this file to specify the layout for tablet of dimension 2048x1536.
If you layouts are properly designed layout-sw720dp should handle both tablets flawlessly.
how can I specify a layout for an specific "resolution" or whatsoever?
For this part there are 2 types of width prefixes. layout-wXXX is for devices whose width is exactly XXX, nothing more, nothing less. Whereas, layout-swXXX is for devices whose width is at least XXX.
Again, well designed layout-sw720dp folder should cover both your needs.

Android : Screen Size

I'm working on android application and got in trouble of multiple screen support. I developed the app for 1080x1920 and when i tested the app on my friends Micromax Unite 2 with resolution of 480x800, it was something else. So i made two folders in the layout as:
layout-1080x1920
layout-480x800
thinking that the 480x800 device will pick up the layout-480x800 folder. But no it used the layout-1080x1920. So what should i do? So that the device having resolution of 480x800 works on layout-480x800
I suggest naming the folders as such:
layout-sw600dp
Where sw600dp means Screen Width 600dp. This layout folder will be used by devices with screen widths of 600dp or more (typically all 7-10 inch tablets, or just very dense screen). And when you are targeting for the phone use just the layout folder without any specified criteria. All phones not matching the sw600dp will use the default layout resources. Possibly also consider using
layout-sw600dp-port
if you need to use specific layouts for portrait orientation, likewise you can do
layout-sw600dp-land
if you wanted to specified layouts for landscape.
The link cricket_007 provided is where I learned this information
Note that 1080x1920 equates to about 540 x 960 dp in dp measurement, which is why I suggested to use the particular 600dp for width
giving the folder names pixel according to android screen support dev page. Even if you know all possible resolutions for every device, the android system takes those *xml files/drawables etc specified by their DPI, not PX. Those dpi resolutions still can change on runtime, such as, when your activity uses a tool bar (which is not part of your dpi resolution). Name your folders layout-xlarge, layout-large, layout-normal, layout-small for *xml layouts. I suggest to put 4 different xml files with same name in each of them and try it again for different devices.

Choosing layout folder for supporting all devices

I got a problem related to the layout folder for some device.
So at first I had layout and layout-large folder. I only have 3 xml files for layout inside of these layouts.
layout folder has xml files with using Eclipse configuration of Galaxy Nexus 4.65" (720x1280 xhdpi)
layout-large folder has xml files using Eclipse configuration of 5.1" WVGA (800x480 mdpi)
I tested it on a small Samsung Galaxy Youth 3.3" (320x480), and it's using layout folder... I don't really understand about screen res, I read it in google doc but until now I don't really get enough of it. Google Nexus configuration looked fit for small screen so I chose it without enough understanding in resolution or screen size. Somehow, it fit well in my Galaxy Youth.
While for larger screen device I depend on layout-large folder, so I tested it with Galaxy Tab 7". It fit well too.
Problem arise when I tested it with Galaxy Note 2 and Galaxy Note 4 .. (for other devices I didn't test because I don't have them).
Galaxy Note 2 and Galaxy Note 4 seems to use layout folder not the large one (I'm sure it'll fit well in my layout-large).
I actually want 320x480 or smaller screen size devices to all use layout and any devices with larger screen should use layout-large. How to achieve that?
YOU CAN USE CODE TO SELECT YOUR DESIRED layout for specific smallest-WIDTH of DEVICE..IN
onCreate:
Configuration config = getResources().getConfiguration();
if (config.smallestScreenWidthDp >= 480) {
setContentView(R.layout.main_activity_LARGE);
} else {
setContentView(R.layout.main_activity);
}
the Document say about ( sw NUMBER dp) format :" The exact point of this switch will depend on your particular design—maybe you need a 720dp width for your tablet layout, maybe 600dp is enough, or 480dp, or some number between these. "
so you can put in res :
res/layout/main_activity.xml
res/layout-sw480dp/main_activity.xml
Look here: http://stefan222devel.blogspot.sk/2012/10/android-screen-densities-sizes.html
There is more information about screen sizes and densities of android devices

Android Text Scaling on different resolutions same density

I have 2 devices, a 1024x600 7" tablet hdpi running Gingerbread and a hub attached to a touchscreen which is 1920x1008 22" in size, hdpi running ICS. The Android OS seems to consider both as "large" (240dp).
So, they have the same actual density (240dpi), same generalized density (hdpi), same generalized size (large) but different actual size (7" vs 22")
The text and spacing dimensions that I specify for my layout work great on the 22", but then on the 7" they look enormous and dont fit on the screen.
I've tried using dp and sp, no difference as I think the problem is that Android sees these things as the same size / density. Does anyone have any recommendations on how I can be able to scale sizes appropriately?
This program wil also eventually need to be supported on a 4.5" handheld as well.
Thanks in advance.
Sorry, my previous answer was completely wrong = )
Ideally, you should be able to design for the 7" tablet and have your layout scale up to the TV. But if that doesn't work you should be able to use something like layout-sw1008dp. The "sw" prefix allows you to specify the minimum dimension of the smallest side of the screen - so in the case of a TV, the height.
I am also facing such problem in my application. But i found a good solution for this.
I have only one layout for tablet and directory name is layout-sw600dp.
Now, when part came to height and width problems, I have created several different values directory in which i place dimensions and font size and other stubs. So there will be no constant value in layout of tablet screen.
androd:layout_width:"60dp" // i drop this scenario
androd:layout_width:"#dimen/tab_width" // i used this scenario
and your values directory name will be like
values-xlarge
values-large
All the values will be fetched from your values directory. It will not create different layout, but one layout can be used multiple times.
See my stack answer which may help you.

Categories

Resources