Creating different layout for android phone and tablet
Asked Answered
C

4

25

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

Constance answered 6/6, 2014 at 4:35 Comment(1)
Create a new project using the "Master/Detail Flow" template. This template creates an app that runs on mobile or tablet (analyse the project to see how the template does that). Then modify the layouts to suit your requirements (change the tablet layout to use a grid instead of the two layouts, or whatever)Tocantins
A
22

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.

Algo answered 6/6, 2014 at 4:52 Comment(0)
A
9

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.

Allisonallissa answered 6/6, 2014 at 4:39 Comment(0)
W
7

Check this out : http://developer.android.com/guide/practices/screens_support.html

You do not need to make two separate apps.

Wolford answered 6/6, 2014 at 4:39 Comment(4)
thanks for your response. I need to know what steps do I follow.Constance
I'd suggest you to read through the link. It explains how to use different layouts for different screen sizes : developer.android.com/guide/practices/…Wolford
Please read meta.stackexchange.com/questions/8231/…Ridotto
I just gave a link because this isn't a question asking how to solve a specific problem. More like a discussion.Wolford
E
1

Here is what I did for the same changing the Recycler View's "app:layoutManager" attribute. Since you are using a list and grid view using the recycler view seems to be the best way to have your scrolling smoothly.

  1. Create a folder in res "layout-sw600dp".
  2. Copy the layout file to this folder.
  3. In the original layout file which is in the layout folder, set linear layout manager as the layout manager attribute.

    <android.support.v7.widget.RecyclerView app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

  4. In the "layout-sw600dp" folder layout file, set GridLayoutManager as the Recycler View attribute.

    <android.support.v7.widget.RecyclerView app:layoutManager="android.support.v7.widget.GridLayoutManager"/>

Do not forget to change the span count because it defaults to a 0 which will be same as the output of the liner layout.

Resources:

  1. How to set RecyclerView app:layoutManager="" from XML?

  2. https://medium.com/google-developers/building-a-responsive-ui-in-android-7dc7e4efcbb3

  3. https://developer.android.com/training/multiscreen/screensizes.html

Euchologion answered 8/3, 2018 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.