Android 中平板电脑的布局
我想在 Android 中为平板电脑和手机创建不同的布局。我应该将布局资源放在哪里才能实现这种差异化?
I would like to create different layouts for tablets and handsets in Android. Where should I put the layout resources in order to make this differentiation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我知道这是一个老问题,但为了它......
根据文档,您应该像这样创建多个资源文件夹
I know this is an old question, but for the sake of it...
According documentation, you should create mutiple asset folders like this
如果您在代码中使用片段概念(意味着多窗格布局),那么最好使用 wdp 而不是 swdp
请参阅表格以了解 wdp
表 2. 屏幕尺寸的新配置限定符(在 Android 3.2 中引入)。
在下面的链接中
http://developer.android.com/guide/practices/screens_support.html
If you are using Fragment concept in the code(means Multi-Pane layout) then its best to use wdp instead of swdp
Refer the table for understanding wdp
Table 2. New configuration qualifers for screen size (introduced in Android 3.2).
In the following link
http://developer.android.com/guide/practices/screens_support.html
对于布局,我相信您当前只能通过以下方式进行区分:
您可以找到有关可以添加到文件夹结构以区分不同设置的更多信息 此处。
最大的问题是Android SDK还没有真正正式融入平板电脑。希望这个问题能够在 Android 的下一个版本中得到解决。否则,您只需确保使用适用于任何屏幕尺寸的缩放布局即可。
With layouts, I believe you can only current differentiate by the following:
You can find more info on what you can add to the folder structure to differentiate between different settings here.
The biggest problem is that the Android SDK hasn't really incorporated tablets officially. Hopefully that will be resolved in the next version of Android. Otherwise, you just need to make sure you use scaling layouts that will work for any screen size.
根据文档,您应该创建像这样的多个资产文件夹..完整列表......
According documentation, you should create mutiple asset folders like this..full list......
Android Studio 中的“预览方向”下拉菜单(如下所示)可以帮助生成快速横向和平板电脑布局 xml。它还为这些布局变体创建单独的文件夹,即
layout-land
和layout-sw600dp
,并将布局 xml 放置在这些文件夹中。"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
andlayout-sw600dp
for these layout variations and place the layout xmls within these folders.此源还提供了如何根据设备配置调用任何资源,如:语言、屏幕宽度/高度、布局方向、屏幕方向等。
您必须小心地创建默认资源,如提到的来源,例如为平板电脑调用高质量的图标。
This source also providing how to call any resources based on device configurations, like: language, screen width/height, layout direction, screen orientation...etc.
You've to be careful to make a default resource as the source mentioned, like calling high quality of icons for tablets.