简体   繁体   English

将限定词添加到布局或值中时会发生什么?

[英]What exactly happens when a qualifier is added to a layout or values?

Something that has been bothering me in android is when I create a layout I have an option to add qualifier. 在Android中困扰我的是创建布局时我可以选择添加限定符。 For instance, when I add a layout I have the option to put in the qualifier of orientation and landscape or portrait. 例如,当我添加布局时,我可以选择放置方向和风景或肖像的限定词。

1) What confuses me is how does android exactly knows which layouts files to use simply by adding a qualifier? 1)让我感到困惑的是,Android如何仅通过添加限定符就准确知道要使用的布局文件?

2) What code keeps track of this resource and called when appropriate because a resource can't just simply determine which files to be drawn from but rather there has to be a code saying which resource to load much like setContentView(). 2)什么代码跟踪该资源并在适当的时候调用,因为资源不仅可以简单地确定要从中提取文件,还必须像setContentView()一样有一个代码说明要加载哪个资源。

When a layout is inflated those properties are read and used. 当布局膨胀时,将读取并使用这些属性。 No one keeps track of them other the developer. 开发人员没有人跟踪他们。

Android chooses the appropriate layout file based on (a) the physical characteristics of the device, eg screen density, and (b) the state of the device, eg orientation. Android根据(a)设备的物理特性(例如屏幕密度)和(b)设备的状态(例如方向)来选择合适的布局文件。

For example, if your phone is high-density, the layout in res/layout-hdpi will be used (if it exists). 例如,如果您的电话是高密度电话,则将使用res / layout-hdpi中的布局(如果存在)。

Or if your phone is in landscape mode, the layout in res/layout-land will be used (if it exists). 或者,如果您的手机处于横向模式,则将使用res / layout-land中的布局(如果存在)。

For more info see: https://developer.android.com/guide/practices/screens_support.html 有关更多信息,请参见: https : //developer.android.com/guide/practices/screens_support.html

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

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