Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating different layout for android phone and tablet

Tags:

This is a basic android question. I have app which need to have different screen design for a phone and a tablet. The phone needs to have a ListView and the Tablet need to have a GridView of items.

I wish to know how can I do this without making two different apps.

Thanks

like image 441
user3713706 Avatar asked Jun 06 '14 04:06

user3713706


People also ask

How do I change the layout of my Android tablet?

"Orientation for preview" dropdown in Android Studio as shown below can help generate quick landscape and tablet layout xmls. It also creates separate folders i.e. layout-land and layout-sw600dp for these layout variations and place the layout xmls within these folders.

How do I change the layout of my Android phone?

Convert a view or layoutClick the Design button in the top-right corner of the editor window. In the Component Tree, right-click the view or layout, and then click Convert view.... In the dialog that appears, choose the new type of view or layout, and then click Apply.

How do I deal with different screen sizes on 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.


2 Answers

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.

like image 157
vyas Avatar answered Oct 27 '22 11:10

vyas


You basically need to provide different layout files for different qualifiers.

As a very brief example, xml layout files places in the layout-sw720dp (or layout-large for API level < 13) folder will be used for devices more than 720 dips wide (i.e. 10" tablets).

Check Supporting Multiple Screens and Providing Resources in the Android documentation.

like image 23
matiash Avatar answered Oct 27 '22 12:10

matiash