【eoe教程】创建支持多种屏幕尺寸的Android应用,2024年最新android实现选择题模式

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

nodpi

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

Resources for all densities. These are density-independent resources. The system does not scale resources tagged with this qualifier, regardless of the current screen’s density.

|- style=" vertical-align:top;"

| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

tvdpi

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

Resources for screens somewhere between mdpi and hdpi; approximately 213dpi. This is not considered a “primary” density group. It is mostly intended for televisions and most apps shouldn’t need it—providing mdpi and hdpi resources is sufficient for most apps and the system will scale them as appropriate. If you find it necessary to provide tvdpi resources, you should size them at a factor of 1.33* mdpi. For example, a 100px x 100px image for mdpi screens should be 133px x 133px for tvdpi.

|- style=" vertical-align:top;"

| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |

Orientation

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

land

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

Resources for screens in the landscape orientation (wide aspect ratio).

|- style=" vertical-align:top;"

| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

port

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

Resources for screens in the portrait orientation (tall aspect ratio).

|- style=" vertical-align:top;"

| style=" border-right:1px solid #ccc;border-bottom:0px solid #ccc; padding:5px 15px; " |

Aspect ratio

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

long

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

Resources for screens that have a significantly taller or wider aspect ratio (when in portrait or landscape orientation, respectively) than the baseline screen configuration.

|- style=" vertical-align:top;"

| style=" border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

notlong

| style="border-right:1px solid #ccc;border-bottom:1px solid #ccc; padding:5px 15px; " |

Resources for use screens that have an aspect ratio that is similar to the baseline screen configuration.

|}

注:如果在Android3.2或者更高版本上开发应用程序,请参阅Declaring Tablet Layouts for Android 3.2章节获取关于新的配置限定符的信息,当申明了指定屏幕尺寸(而不是使用表1中的尺寸限定符的布局资源时,你应当使用这些限定符。

获取更多关于这些限定符如何大致对应于真实的屏幕尺寸和密度的信息,请参阅本文中前面提到的支持的屏幕范围章节。

例如,下面是应用程序中的资源目录列表,这个程序为中等、高及超高密度屏幕提供了不同的为不同屏幕尺寸和位图绘图设计的布局。

res/layout/my_layout.xml // 标准屏幕尺寸的布局(“默认”)

res/layout-small/my_layout.xml // 小屏幕尺寸的布局

res/layout-large/my_layout.xml // 大屏幕尺寸的布局

res/layout-xlarge/my_layout.xml //超大屏幕尺寸的布局

res/layout-xlarge-land/my_layout.xml // 横向超大的屏幕布局

res/drawable-mdpi/my_icon.png // 中等密度的位图

res/drawable-hdpi/my_icon.png //高密度的位图

res/drawable-xhdpi/my_icon.png // 超高密度的位图

如需要更多关于如何使用替代资源和完整的配置限定符列表(不仅仅是屏幕配置)的信息,请参阅Providing Alternative Resources。

请注意,当Android系统挑选资源时,它采用一定的逻辑来判定“最匹配”资源。也就是说,使用的限定符没必要在所有情况下,为了系统能用到它而严格匹配当前屏幕配置。具体来说,当基于尺寸的限定符选择资源时,如果没有更匹配的资源,系统会使用比当前屏幕更小的屏幕资源(例如,必要时,大尺寸屏幕将会使用标准尺寸屏幕资源)。但是,如果唯一可用的屏幕资源比当前屏幕大,系统将不会使用它们,而且如果没有其他匹配设备的配置的话,应用程序将会崩溃(例如,如果所有布局资源都被标记为xlarger限定符,但是设备是一个标准尺寸的屏幕)。更多关于系统如何选择资源的信息,请阅读How Android Finds the Best-matching Resource章节。

小提示:如果你有一些系统从未调整过的绘图资源(或许因为在运行时对其进行了调整),应当把他们放置在nodpi配置个限定符的目录。有这些限定符的资源被认为是密度不可知的资源,系统将不会调整它们。

设计可替代的布局和绘图


应该创建的可替代资源的类型取决于应用程序的需要。通常,应该使用尺寸和方向限定符提供可替代的布局资源,使用密度限定符去提供替代的位图绘图资源。

下面的段落分别总结了应该如何使用尺寸和密度限定符来提供替代的布局和绘图。

可替代的布局

一般情况下,一旦在不同屏幕配置上测试应用程序,应该知道是否需要为不同屏幕尺寸创建可替代的布局。例如:

  • 当在小屏幕上测试时,可能会发现,布局不是很适合这个屏幕。例如,一排按钮可能不适合在小屏幕的设备的屏幕宽度内。这种情况下,应该为小屏幕提供一种可替代的布局,即通过调整这些按钮的大小或位置。

  • 当在超大屏幕上测试时,可能会意识到,布局并没有有效地利用

  • 8
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值