How to support layout for xhdpi and xxhdpi devices? - android

I am facing layout problem to support xhdpi and xxhdpi devices. As far as I know, android has no support for layout-xxlarge or layout-xxhdpi. Android use layout-xlarge to support both xhdpi and xxhdpi. For this reason, I am facing problem. Basically problems are two types. One is the top margin issues. Is there any way to set the top margin for both xhdpi and xxhdpi devices. I can't use LayoutParams or ViewGroup.MarginLayoutParams. The reason is I am using LinearLayout to define weightSum of children LinearLayout. Inside the children LinearLayout, I am using RelativeLayout for my layout.

The reason is that as of Android 3.2, the layout-xlarge, large, normal, small are all deprecated, and new identifiers were introduced, which you can find here Supporting Multiple Screens | Android Developers
Declaring Tablet Layouts for Android 3.2
For the first generation of tablets running Android 3.0, the proper way to declare tablet layouts was to put them in a directory with the xlarge configuration qualifier (for example, res/layout-xlarge/). In order to accommodate other types of tablets and screen sizes—in particular, 7" tablets—Android 3.2 introduces a new way to specify resources for more discrete screen sizes.

You should create dir with needed name like layout-xxhdpi
See http://developer.android.com/guide/practices/screens_support.html#NewQualifiers

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?

What is difference between layout-small and layout-sw320dp

I know how to use the following folders but for example I do not know what is difference between layout-small and layout-sw320dp?
Also, Suggest for me that which the folders are important to optimization.I do not like my program be seen for users as irregular.I want a final answer from you.
Based on which the folders I design my layouts? Because I have not multiple android devices to test the layout in different screen size.
I know how to use the folders and I have not problem about it.but my question is which the folders for continuous use and for all devices?
layout-sw320dp
layout-sw480dp
layout-sw600dp
layout-sw720dp
layout-small,
layout-large etc...
Both are qualifiers to define layouts for specific screen sizes.
Before Honeycomb - 3.0 (I guess), the screen's diagonal size was measured based in 4 groups: small, normal, large, and extra-large.
After that layout resources are defined for screen sizes with the smallest width (sw stands for smallest width).
Resuming, layout-small is deprecated and layout-swXXXdp qualifier should be used instead.
You can get more info about these qualifiers in Supporting Multiple Screen's Android official doc page.
The difference is that the qualifiers -small, -normal, -large had been marked as deprecated in API 13. Now the recommended way to go is using the -swdp folder structure. (see http://developer.android.com/guide/practices/screens_support.html#support )
The number of resources folders in your project depends basically on the type of devices you're targeting at (small phones, phablets, tablets, ...) and the number of different layouts you want to maintain. In most cases implementing a layout for landscape/portrait modes for phones and for tablets should be enough. Though you can create another layout for a specific screen size if you really need it.
Hope this helps.

Android - standard layout folder, which screen size?

I'm implementing an application and I want to support all screen sizes. I have 4 layout folders: layout, layout-small, layout-large and layout-xlarge.
Which screen size supports the standard layout folder? Is it even necessary?
Which screen size supports the standard layout folder?
In your case, it will depend on what files are in what directories.
Let's say that you have main.xml in layout/, and not in any of the other three candidates. Then, setContentView(R.layout.main) will use the copy in layout/.
Now, let's say that you add a revised version of main.xml in layout-xlarge/. On an -xlarge device, Android will use the layout-xlarge/ version of main.xml, and on other screen sizes, Android will use the layout/ version of main.xml.
Now, let's say that you add a third main.xml version, this time in layout-small/. Android will still use the layout-xlarge/ copy of main.xml for -xlarge devices. However, all other devices will use layout-small/, and the layout/ copy of main.xml will be ignored. Android will not try to shrink a layout from a larger size (e.g., -xlarge layout on a -normal device), but it will try to expand a layout from a smaller size (e.g., a -small layout on a -normal device).
What I tend to do is use layout/ for:
Layouts that do not need different versions for different sizes
Layouts to be used on -normal devices (as I rarely support -small)
I then use layout-large/, layout-xlarge/, or their Android 3.1+ replacements (e.g., layout-w720dp/) for layouts to be used on larger screen sizes.
However, that is just my particular style, and you are welcome to do what you want, within the usage rules described above.
using modern notation is a better solution:
/layout // for phones
/layout-sw600dp // for 7 inch tablets
/layout-sw720dp // for 10 inch tablets
In popular:
Mdpi screen smartphone is cheap
Hdpi screen smartphone is expensive.
If you use layouts only mdpi folder, this layout will be used for all screens
Legend:
layout-small = ldpi
layout = mdpi
layout-large = hdpi
layout-xlarge = xhdpi

The same layout displays no alike in xlarge screen between Android 2.3 and 4.x

[Update] Thanks Kai, this issue is caused by #dimen/activity_vertical_margin in XML. The default value of dimens.xml is 128dp in values-sw720dp-land. (others are 16dp).
I create a new empty project, and run it on Android 4.2 and 2.3 (with Xlarge screen 10.1" WXGA 1280 x 800). Here are the screen capture. Why does "Android 4.x" and "XLARGE" screen cause the content indention?
(Android 2.3)
(Android 4.2)
Besides using the Xlarge qualifier for layouts you also can use version numbers. I'm not sure why it would be different if it is the same resolution and screen size but you can also use version qualifiers for your layout folders.
So, you could have one that is in res/layout-v15 (4.x) and one in `res/layout-xlarge(since its working in 2.3)
This should make devices with 4.x use use the layout-v15 and anything below with the appropriate screen size would use layout-xlarge. I don't know if this will take care of all your problems but it may help.
It looks like a very larg marginLeft and marginRight is applied to the 4.x version of the dialog:
You should check your XML and image resources to see if different margin is applied for different API level.

layout-xxhdpi/layout-xxlarge not supported on Android Studio

Not supported on Android Studio. I want to create a layout new phones, like Galaxy S4. I have one to test on and the sizes are too small. But android studio compiler gives an error, because that forward slash is appearing. I tried layout-xxlarge, it give an error too.
android-apt-compiler: [xxxxxxxxxx] invalid resource directory name:
C:\Users\xxxxxxxxxxxxxx\Dropbox\android_studio_workspace\xxxxxxxxxxxxxxxxx\res/layout-xxlarge
Are these layouts supported on Eclipse?
As you can see here, section "Declaring Tablet Layouts for Android 3.2":
For the first generation of tablets running Android 3.0, the proper
way to declare tablet layouts was to put them in a directory with the
xlarge configuration qualifier (for example, res/layout-xlarge/). In
order to accommodate other types of tablets and screen sizes—in
particular, 7" tablets—Android 3.2 introduces a new way to specify
resources for more discrete screen sizes. The new technique is based
on the amount of space your layout needs (such as 600dp of width),
rather than trying to make your layout fit the generalized size groups
(such as large or xlarge).
The best you can get is:
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
The ones you need are defined here.

Categories

Resources