Android, different layout for 10.1 and 9.7 inch displays

1.8k Views Asked by At

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!

3

There are 3 best solutions below

2
On BEST ANSWER

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.

1
On

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.

0
On

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.