I have two layout folders, layout-sw600dp
for 7" Tablet (1024X600) mdpi and another with name layout-xlarge
for 12" Tablet (1280X800) mdpi. The problem is that when I run my project in 7" emulator it pics the layout from layout-xlarge
folder instead of layout-sw600dp
. I have also tried other solutions by changing folder names which are given in different sites but could not find the suitable solution for my problem. Please provide me a working solution for this problem. Thanks in advance.
The thing to remember here is that using the swXXXdp
resource identifier only works on devices that are running Android 3.2+ (which is when it was added). Older devices will not recognize and therefore will not use these identifiers, so you must use the old identifiers (small
, normal
, large
, xlarge
) if you intend on supporting tablets running Android < 3.2. As of now, only 0.3% of tablets out there run Android 3.1 (API 12), so it's a safe call to not fully support them - http://developer.android.com/about/dashboards/index.html.
There is an excellent blog explaining how to use these newer resource identifiers. http://android-developers.blogspot.com/2011/07/new-tools-for-managing-screen-sizes.html
For your particular issue, assuming you are only supporting Android 3.2+ for your tablet layouts, change your layout-xlarge
folder to layout-sw720dp
to support 10"+ tablets, and your layout-sw600dp
will support 7" tablet layouts.
The options for layout folders are vast. Not only can you specify things like layout-land/
or layout-large
, you can also specify mixtures of them, like layout-large-land/
or layout-xhdpi-land/
. You can see all of the qualifiers here at Android Developers.
For your problem, check to see if the dimensions of your tablet emulator is of the correct screen resolution. You can specify a specific screen resolution when creating an AVD. Also, when specifying layout-sw600dp/
, it checks for the width of the actual available width of your currently running actiity. On tablets running 4.2, for instance, ~50dp of the bottom of the screen is used for the system bar, and some are used for the top action bar if not in fullscreen. These would reduce the actual dp to less than 600.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With