简体   繁体   English

Android中默认布局的分辨率是多少?

[英]What is the resolution of default layout in Android?

I am just using simple default layout and not adding any of these layout versions; 我只是使用简单的默认布局,而不添加任何这些布局版本; l-dpi-Layout , m-dpi-layout etc.. then what exactly the resolution of my default layout is ? l-dpi-Layoutm-dpi-layout等。 那么我的默认布局的分辨率到底是多少?

Let say i add an image and define its width-height as 20dp X 20dp . 假设我添加了一个图像并将其width-height定义为20dp X 20dp This image is looking perfect in layout Preview screen, but would it look same in 1440X2560 screen or 1920X1080 screen. 该图像在“ layout Preview屏幕中看起来很完美,但是在1440X2560屏幕或1920X1080屏幕中看起来还是一样。

My concerns are: 我担心的是:

  1. what exactly is the resolution of default layout is? 默认布局的分辨率到底是多少?
  2. How would android know that the 20 dpi i am defining fits best for 1080X1920 resolution and 27dpi fits best 1440X2560 screen , when i am writing 20dpi in my default layout which perfectly fits in layout preview screen 怎么会知道的android的20 dpi我定义最适合为1080X1920的分辨率和27dpi最适合1440X2560 screen ,当我写20dpi ,其中完全符合我的默认布局layout preview

The system assumes a target device with a density of 160dpi. 系统假定目标设备的密度为160dpi。 When you define the size of yout image with dp unit, Android adapts the size according with the resolution of the device. 当您使用dp单位定义yout图片的尺寸时,Android会根据设备的分辨率调整尺寸。 For example, if you put an image of 100dp x 100dp in a 160dpi device it will take 100 x100 pixels, but in a device with a 640dpi screen it will take 400 x 400 pixel 例如,如果将100dp x 100dp的图像放置在160dpi的设备中,它将占用100 x100像素,但是在具有640dpi屏幕的设备中,它将花费400 x 400像素

  1. By default when you create a template app, your main content layout has two parameters values as layout_width=match_parent and layout_height=match_parent . 默认情况下,创建模板应用程序时,主内容布局具有两个参数值,例如layout_width = match_parentlayout_height = match_parent match_parent value means whatever the screen dpi size the mobile has, it stretches all the way to its size of width and height respectively which is calculated by android automatically when it runs its layout pass to position views (including padding). match_parent值表示无论移动设备具有的屏幕dpi大小,它都会一直扩展到其宽度和高度,这是android在将布局传递到位置视图(包括填充)时由android自动计算得出的。 So in this context the default resolution of your layout is what your mobile has minus the size of statusBar and navigationBar. 因此,在这种情况下,布局的默认分辨率是您的手机的默认分辨率减去statusBar和navigationBar的大小。
  2. Android translates the DPI value you enter for your width and height into number of pixels internally to size your views. Android将您为宽度和高度输入的DPI值转换为内部像素数以调整视图大小。 You can also put the size of your view into number of pixels but its not recommended. 您也可以将视图的大小设置为像素数,但不建议这样做。

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

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