Creating different layout for android phone and tablet

可紊 提交于 2019-12-24 20:24:15

问题


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


回答1:


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.




回答2:


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.




回答3:


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

You do not need to make two separate apps.




回答4:


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



来源:https://stackoverflow.com/questions/47653996/different-layout-for-mobile-phone-and-tablet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!