简体   繁体   English

Android:哪个屏幕尺寸选择了dimens.xml文件?

[英]Android: Which dimens.xml file picked for what screen size?

If I have a table layout with say 2 rows and 2 columns. 如果我有2行2列的表布局。 Each quadrant table box has static text like "box_11", "box_12", "box_21", "box_22". 每个象限表框都有静态文本,例如“ box_11”,“ box_12”,“ box_21”,“ box_22”。 I want the text size to be bigger for bigger screen and smaller for small screens. 我希望较大的屏幕上的文本大小更大,较小的屏幕上的文本大小更大。 I want the text to scale according to the screen size. 我希望文本根据屏幕尺寸缩放。 How should I do it? 我该怎么办?
I guess I should be using dimens.xml file, defining: 我想我应该使用dimens.xml文件,定义:
<dimen name="activity_text_size">15sp</dimen>
Then I should be using android:textSize="@dimen/activity_text_size" 然后我应该使用android:textSize="@dimen/activity_text_size"

I see that there are different "values" directories like values, values-sw600dp, values-sw720dp_land, values-v11, values-v14 in my project workspace. 我看到在我的项目工作区中有不同的“值”目录,例如值,values-sw600dp,values-sw720dp_land,values-v11,values-v14。 Each 'values'directory can have a dimens.xml file. 每个“值”目录可以具有dimens.xml文件。 On what basis a dimens.xml is picked when you have multiple files? 当您有多个文件时,将基于什么基础选择dimens.xml?

for example: 例如:

//into dimen.xml(600dp) //放入dimen.xml(600dp)

<resources> <dimen name="activity_text_size">15dp</dimen> </resources>

//into dimen.xml(sw720dp_land) //进入dimen.xml(sw720dp_land)

<resources> <dimen name="activity_text_size">20dp</dimen> </resources>

//into dimen.xml(w820dp) //进入dimen.xml(w820dp)

<resources> <dimen name="activity_text_size">25dp</dimen> </resources>

and for any size of screen you shoud use specific dimen.xml(your size target )and use same dimen.name for it . 对于任何尺寸的屏幕,您都应使用特定的dimen.xml(您的尺寸目标)并为其使用相同的dimen.name。

With reference to @matiash's link and another official resource: - http://developer.android.com/guide/topics/resources/providing-resources.html#BestMatch - https://developer.android.com/guide/practices/screens_support.html 关于@matiash的链接和其他官方资源,请参考:-http: //developer.android.com/guide/topics/resources/providing-resources.html#BestMatch-https : //developer.android.com/guide/practices/ screens_support.html

The 'standard' densities that are catered for are: 可以满足的“标准”密度是:

A set of six generalized densities: 一组六个广义密度:

  1. ldpi (low) ~120dpi ldpi(低)〜120dpi

  2. mdpi (medium) ~160dpi mdpi(中)〜160dpi

  3. hdpi (high) ~240dpi hdpi(高)〜240dpi

  4. xhdpi (extra-high) ~320dpi xhdpi(超高)〜320dpi

  5. xxhdpi (extra-extra-high) ~480dpi xxhdpi(超高)〜480dpi

  6. xxxhdpi (extra-extra-extra-high) ~640dpi xxxhdpi(超高)〜640dpi

When you create your application with multiple dimen.xml files, the one that is suited for that screen size is chosen. 当您使用多个dimen.xml文件创建应用程序时,将选择一个适合该屏幕尺寸的文件。

If in the instance that a resource is not provided for that specific screen density: 如果在这种情况下没有为该特定屏幕密度提供资源:

If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and density 如果没有可用的匹配资源,系统将使用默认资源并根据需要将其放大或缩小以匹配当前屏幕尺寸和密度

Hope this helps you :) 希望这对您有所帮助:)

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

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