Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I target 1280x720 WXGA720 resolution (like new Galaxy Nexus) in Android Layout folders?

When testing my application at WXGA720 resolution on the Android Emulator running 4.0.3 Ice Cream Sandwich, my app takes the layout assets from the layout-normal-land-854x480 folder in landscape view and the layout-port-480x320 folder for portrait view. I would like to be able to specifically target this resolution so my app displays properly on the new phones. How do I do this? I have tried the following...

layout-normal-land-xhdpi
layout-normal-port-xhdpi
layout-normal-land-xlarge
layout-normal-land-large
layout-normal-land-1280x720
layout-normal-port-1280x720, etc...

...and it still takes the assets from the wrong folders detailed above.

My app is targeting Android 2.1 (which I assume is still the standard target these days), so I can't as far as I know use the new layout qualifiers. Is this a bug? Has anyone had this same issue and found a workaround?

I have the following folder configuration, and all of the other AVDs display as expected:

layout
layout-land
layout-normal-land-480x320
layout-normal-land-854x480
layout-port-480x320
layout-port-800x480

like image 272
Matt W Avatar asked Jan 25 '12 16:01

Matt W


People also ask

How to set layout for different screen size in Android?

The best way to create a responsive layout is to use ConstraintLayout as the base layout in your UI. ConstraintLayout enables you to specify the position and size of each view according to spatial relationships with other views in the layout. All the views can then move and resize together as the screen size changes.

What does smallest width do?

The smallest width qualifier specifies the smallest of the screen's two sides, regardless of the device's current orientation, so it's a simple way to specify the overall screen size available for your layout.


2 Answers

When testing my application at WGXA720 resolution on the Android Emulator running 4.0.3 Ice Cream Sandwich, my app takes the layout assets from the layout-normal-land-854x480 folder in landscape view and the layout-port-480x320 folder for portrait view.

If I had to guess, you do not have a valid <supports-screens> element (or possibly no android:minSdkVersion) in your manifest, and so you are being thrown into a compatibility mode.

Also, please don't use suffixes like -480x320 and -854x480. These were removed from the documentation for a reason. Whatever problem you think you are solving with them can be better solved some other way.

My app is targeting Android 2.1 (which I assume is still the standard target these days), so I can't as far as I know use the new layout qualifiers.

You can set your build target to a higher level and use the new layout qualifiers. However, older devices will ignore them, so you will still need to use -normal and -land and kin for them, in parallel with any resource sets with the new qualifiers. You can create resource aliases to minimize code duplication.

like image 195
CommonsWare Avatar answered Nov 14 '22 23:11

CommonsWare


I was having a similar problem displaying my layouts properly but I was using the HTC Rezound that has 1280 by 720 resolution. It uses Android version 2.3.4. My screens were only showing on the upper portion of the display and the bottom third was black. Everything was displaying properly using lower resolution phones.

I went through the exercise of making new layout directories ( layout-xhdpi, layout-large, layout-1280x720, layout-1200x700, etc) and modifying my layout files to match the larger resolution, but each attempt failed and the app always showed in the upper part of the screen only. I had read the docs from http://developer.android.com/guide/practices/screens_support.html and did not find anything that solved the problem. I finally fixed it, and the solution had nothing whatsoever to with adding new layout directories set up for higher resolutions! The solution was all about the "uses-sdk" statement in the AndroidManifest.xml file. My original manifest contained the statement:

<uses-sdk minSdkVersion="8"/>

With only the minimum sdk version specified, the graphics would not display properly on the Rezound. However, after changing only one line in the AndroidManifest.xml (and making no other changes) the phone displayed all the screens properly:

<uses-sdk android:targetSdkVersion="9" minSdkVersion="8" />

Why did this fix it but not the documented methods? I don't know! I am finding many hidden connections in Android that seem to defy a logical explanation. Can someone explain to me why changing the uses-sdk statement is critical to displaying on a higher resolution display?

like image 26
Tary Avatar answered Nov 15 '22 00:11

Tary