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
"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.
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.
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.
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.
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.
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