Android studio layout size folders - android

I'm trying to create a different layout for 1080dp and others using
"layout-sw1080dp" folder but it seems android studio completely ignores it and loads from the default layout folder.
I've tried another way - setting different dimensions using values-sw1080dp and still nothing!
What is the correct way to write different layouts for different screen sizes?

DP is not the same as PIXEL!!!
You think it's ignoring because devices with 1080dp do not exist (yet?).
values-sw720dp: that's for Nexus 9 and 10 inch tablets
values-sw600dp: that's for 7 to 8 inch tablets
values-sw360dp: that's for small phones
I suggest you installing this app https://play.google.com/store/apps/details?id=nl.qbus.sizemeup&hl=en on your devices, it shows the size of each devive in pixels and in DP.
Also, read more about it here http://developer.android.com/guide/practices/screens_support.html

By default, Android Studio (version > 0.8) groups resources with the same name into one folder, with their distinguishing qualifiers in a muted grey. Be sure you're also using the correct qualifiers.

The modifier you're using sw<N>dp (smallest width) represents resources for the shortest of the screen's available height and width.
Are you sure your shortest screen's dimension are not less than 1080dp?
Read more about resource folder modifiers here.

Related

How to create layouts for specific devices such as 8 fold-out?

I'm trying to create layouts for various screen sizes. I have used resource qualifiers to add sw600dp and sw720dp layouts, which work well with tablets in the emulator, but I want to make some specific layouts for foldable phones, starting with an 8 fold-out, which in device manager is said to have a resolution of 2200x2480, and displaymetrics confirms that the emulator has a screen width of 2200 pixels. I made a layout using qualifiers of w2200dp-h2480dp, but this is not used when I run the emulator (the sw720dp layout is chosen instead). I thought maybe the issue is using px instead of dp, so I've also tried w835dp-h945dp (as specified for a generic 8 fold-out device in the design preview window layout options), also w787dp-h837dp (derived from the formula dp = (px/dpi)x160 applied to 2200x2480), but none of these is used when I run the emulator.
How can I create layouts for this and other specific screen sizes? Am I going about it the wrong way?

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.

5.2'' and 5.0'' screen support on android devices

I have been struggling with this problem about a week and can not figure out how to make it work. I have some views on a screen. And one values\dimens.xml(sw320dp-xxhdpi) resource file. Also I have nexus 5.2 1080*1920 420dpi and nexus 5.0 1080*1920 xxhdpi. The layout appears differently on both screens. How to make it display the same on each device?
What resource file should I add (if it is any)?
How to add for example values\dimens.xml(1080*1920 420dpi)?
I think your layout is simply built as poorly scaling. Unless you have some very specific use case, you need to make sure your layout fills the area it is provided with regardless.
As for the resource folder, if you want to make sure the same layout file is used on large screens, it is enough to put it in the folder layout-sw360dp. If you have xxhdpi devices with the resolution 1080x1920, Android will select the same file for both since the smallest side will be exactly 1080 / 3 = 360 density-independent pixels.
How to make it display the same on each device?
In general it's impossible for all Android devices. I think best solution - using VectorDrawable or SVG format and scale vectors for each device.

Android Layout for 720x720 BlackBerry screen

My BlackBerry Q5 can run Android applications and I'd like to optimize one of my existing apps for its screen. The resolution is 720x720, but the runtime also inserts a bar in the bottom of the screen, so usable resolution for Android app is 720x620 pixels, so I guess that's what the phone reports to Android app as the resolution.
Is there a way to make a layout that will apply only to 720x620px screens? The documentation for supporting multiple screen sizes says that there are w<N>dp and h<N>dp qualifiers, but they use scaled dp units and also means minimum available width in dp units, so they would not be useful in here.
I needed to solve your problem too, this is my solution.
The Q5 and Q10 screen density is xhdpi (scale factor of 2.0) so max screen size is 720x720px / 2.0 = 360x360dpi
Quoting from the documentation, Table 2, "Available height" row:
Specifies a minimum available screen height, in "dp" units at which
the resource should be used
[...]
When your application provides multiple resource directories with
different values for this configuration, the system uses the one
closest to (without exceeding) the device's current screen height.
[...]
Added in API level 13.
Based on these, for Androids with API>=13 (including Blackberrys) you can put your Blackberry specific layout in "layout-h240dp" folder and all the others in "layout-h361dp"
Blackberry height is greater than 240dp and less than 361dp, so it will use layouts in h240dp folder.
Notes:
- If you don't add the 361dp folder, the 240dp folder will be used for every device with height greater than 240dp.
- I choose 240dp because it is a common minimium dimension for today devices.
- 309dp should work too as it less than 310dp (minimum height of BB's screen with bars)
- For Androids with API<13 you have to put a default layout in the generic "layout" folder, because the previous "h*dp" folders are ignored. if default layout is missing, the app should crash.
I don't mean to turn this into a full-blown answer, but I need the extra space.
For your assets, if you'd like to target them specifically for Q5 or Q10 devices, place them in the drawable-square folder. This changed from drawable-small-square due to deprecation.
If you plan on deploying to OS 10.2.1+ devices and don't want that back-bar to show by default, you can add a small configuration file to your app so that the system knows not to show it.
For more information on that, take a look at my blog:
Android Developers: Eliminate the Back-Bar in Your 10.2.1. App

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