Layout for Tablets in Android

Layout for tablets in Android

I know this is an old question, but for the sake of it...
According documentation, you should create mutiple asset folders like this

res/layout/main_activity.xml           # For handsets (smaller than 600dp available width)
res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger)

How to create a Layout for Tablet

The documentation you are looking for is here . The value you should be using is 600dp as described in the docs

res/layout-w600dp/main_activity.xml # For 7” tablets or any screen with 600dp
# available width (possibly landscape handsets)

So basically you can create a layout-w600dp folder inside of the res directory to be used as the layout for tablets.

Creating different layout for android phone and tablet

Basically you have to make different layouts for both android phone and tablets. Android is smart enough to differentiate. For example for large screen you can just make a new folder namer Layout-large. and put your tablet xml in it. Android will pick xml from here and in case of phone it will pick from simple layout folder.
The configuration qualifiers you can use to provide size-specific resources are small, normal, large, and xlarge. For example, layouts for an extra large screen should go in layout-xlarge/.

I would recommend if both phone and tablet screens and totally different you can make two different apks and load on same Id on google play. This way your application will be light weight and will be be fast. Google play automatically can detect that application is for tablet or or phone.You need not to worry about that.

Creating layout for tablet and phone android

You can use these layouts to support all screen sizes:

layout # For handsets (smaller than 600dp available width)

layout-sw600dp # For 7” tablets (600dp wide and bigger)

layout-sw720dp # For 10” tablets (720dp wide and bigger)

How can i made the layout that will work in both Tablet and phone?

Make your resource like this.

res/layout/my_layout.xml // layout for normal screen size ("default")

res/layout-small/my_layout.xml // layout for small screen size

res/layout-large/my_layout.xml // layout for large screen size

res/layout-xlarge/my_layout.xml // layout for extra large screen size

res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

res/drawable-mdpi/my_icon.png // bitmap for medium density

res/drawable-hdpi/my_icon.png // bitmap for high density

res/drawable-xhdpi/my_icon.png // bitmap for extra high density

For more reference. reference1.

Add this in your manifest.xml

<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens= "true"
android:anyDensity="true"
/>

Hope this will help you.

How to make layout for 8 inch tablet

sw720dp will do it for you. Because 8 inch tablet lies in the bucket sw720.

Android, different layout for 10.1 and 9.7 inch displays

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.

How can I set a landscape layout just for tablets?

Put the tablet layout in your res/layout-w600dp or whatever smallest width you want to support for the two pane layout.

How to create two separate layouts for 10'' and 9.7'' tablets?

I need two folders: one for 10'' tablets and another for 9.7''

Those are not meaningful figures, and therefore there is no means of having different resources for them. They are not meaningful, because they do not take aspect ratio into account. Not all Android devices have the same aspect ratio: some are 16:9, some are 16:10, some are 4:3, some are 1:1, some are other things entirely. 10", 9.7", and kin are primarily for marketing purposes.

This is no different than in Web design, where designers don't speak in terms of the diagonal dimension of a browser window all that much.

For technical purposes, while you can use the legacy -large/-xlarge sorts of qualifiers, they were supplanted about four years ago by the -w/-h/-sw qualifiers:

  • -w640dp indicates resources that should only be used on devices whose current width is 640dp (i.e., 4 inches) or larger, where you can supply the number you want where I have 640

  • -h640dp indicates resources that should only be used on devices whose current height is 640dp or larger (again, with customizable values)

  • -sw640dp indicates resources that should only be used on devices whose smallest width, in any orientation, is 640dp or larger (in landscape, the "smallest width" is actually the current height)

This gives you control much like how Web designers use media queries in CSS stylesheets to change CSS rules based on particular heights and widths.

Now, since nobody knows what you think is a 9.7" UI and what you think is a 10" UI, nobody can really help you either consolidate that into one set of layout rules or provide you with qualifier values that will work. You are going to need to determine for yourself where your dividing line is, based on current width, current height, or smallest width. Let's pretend for the moment that you choose 800dp current width as being your dividing line. Your smaller-than-800dp layouts would go in directories like res/layout/ and res/layout-land/. Your 800dp-or-larger layouts would go in res/layout-w800dp/.

I have tried several answers saying to rename the folder to /layout-sw768dp/, but they don't work.

You may wish to consider editing your question and explaining what "they don't work" means.



Related Topics



Leave a reply



Submit