Petros Mastrantonas
Petros Mastrantonas

Reputation: 1046

Trouble creating the right layout folder for 9.7 Tablets and 4:3 aspect ratio

Right now I have three layout folders: layout, layout-sw600dp and layout-sw720ddp

Now I am getting reports that certain china tablets who often have the aspect ratio of 4:3 and are 9.7 inch won't show everything on the display. (UPDATE: apparently 9.7 are the hot new thing and everybody is releasing them now, like the Nexus 9 and budget tablets by Samsung)

I have scrollviews in almost all of my views so thats not really a problem and most of the layouts should adjust just fine that way but for the one view which can not be fitted with a scrollview I would like to create separate layouts.

These are the stats of the problematic tablets: 1024px x 768px 9.7 (4:3 aspect ratio) and 2048px x 1536px 9.7 (4:3 aspect ratio)

Now my problem is, that I dont really know how to name the folder to only target the specific tablets without tempering with the other device who get targeted by layout-sw600dp and layout-sw720dp.

I tried those various dp calculators I found online but they all dont seem to take the 4:3 ratio into account.

To make matters worse, I don't have those devices at hand, so testing is also problematic, has anyone succesfully created such a device with the emulator? If yes, could you also give me a hand on the right parameters?

Thanks for the help in advance.

UPDATE: I think the answer is to rename layout-sw720dp to layout-sw800dp and create a new folder layout-sw768dp for the 9.7 tablets. so far in the preview it looks good and 10 inch tablets also choose the layout-sw800dp folder then again, i dont have any real 9.7 inch devices to test.

I also tried layout-w768dp-h1024dp but this always got ignored. Also layout-h1024 didnt work. Any clues why?

my uses-sdk in the manifest:

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

Upvotes: 0

Views: 344

Answers (1)

Gani
Gani

Reputation: 3

I've also faced same issue and it took 2 days to find out the solution.

Most of 10 and 10.1 inch tablet are 1280dp width and 9.7 inch 4:3 aspect ratio tablet is of 1024dp width. If you want to support 9.7 inch tablet along with 10,10.1, and if you've any views that you want to customize it separately for 9.7 inch tablet. Then do the following thing.

Add two more folders layout-w1024dp (for 9.7 inch tablet) and layout-w1280dp (for 10& 10.1 inch tablet) and add your corresponding layouts to these folders.

You can can calculate the width of the tablet in dp using following code

    Display display = getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);

    float density = getResources().getDisplayMetrics().density;
    float dpWidth = outMetrics.widthPixels / density;

    Log.d("Display", "Width in Pixel: " + outMetrics.widthPixels + " | " + "Width in DP: " + dpWidth + " | " + "Device density :" + density);

Upvotes: -1

Related Questions