简体   繁体   English

创建不同屏幕布局的最佳实践

[英]The best practice to create different screens layouts

I'm developing an Android app that is capable of running on different screens, I'm using on of the approachs explained here which is: 我正在开发一个能够在不同屏幕上运行的Android应用,在这里介绍的方法之一是:

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)

I know that the Layout folder is the default one that the app goes to when not finding the desired layout in the specified folder, but I want to ask if I've like Two Layouts ( layout_A & layout_B ) and layout_A is differ from one case to another of the mentioned three cases( handset , 7' , 10' ) so that it will be exist in the three folders, but the layout_B is differ from handset to 7' but is the same from 7' to 10' , am i suppose to copy/paste it from the 600dp folder to the 720dp folder ?(as if the layout folder is the default as always) , or it's enough to put in the 600dp folder and it will be accessed from there in the case of 720dp ?. 我知道Layout文件夹是在指定文件夹中找不到所需布局时应用程序转到的默认文件夹,但是我想问一下我是否喜欢两个Layouts( layout_Alayout_B )和layout_A与一种情况不同到上述三种情况中的另一种( 手机7'10' ),以便它存在于三个文件夹中,但是layout_B手机7'有所不同,但从7'10'却相同假设将其从600dp文件夹复制/粘贴到720dp文件夹(好像布局文件夹始终是默认文件夹),或者足以放入600dp文件夹,而在720dp的情况下可以从那里访问它? 。

ie. 即。 if I've the Layouts folders as the following: 如果我具有以下布局文件夹:

layout/layout_A.xml       //A1
      /layout_B.xml       //B1

layout-sw600dp/layout_A.xml      //A2
              /layout_B.xml      //B2

layout-sw720dp/layout_A.xml      //A3

And now I'm trying to run layout_B.xml on a 10' tablet, what's the layout that my app will pick ? 现在,我试图在10英寸的平板电脑上运行layout_B.xml ,我的应用程序将选择哪种布局? (B1 || B2) ? (B1 || B2)

As I understand the configuration examples it would work if you put your Layout_B only inside the res/layout-sw600dp/ folder and it will be used by a 720dp device as well, because the sw means "smallest width" and a 720dp device provides the requested minimum of 600dp (and extends this requirement by additional 120dp), which means in your case the app will pick B2 for the 10' tablet. 据我了解配置示例 ,如果仅将Layout_B放在res/layout-sw600dp/文件夹中,它将720dp ,并且720dp设备也将使用它,因为sw表示“最小宽度”,而720dp设备提供了要求至少600dp(并将此要求增加120dp),这意味着在您的情况下,应用将为10英寸平板电脑选择B2

Testing both configurations will make this sure in a minute. 测试这两种配置将在一分钟内确保这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM