ANDROID:适用于不同尺寸的ImageView [英] ANDROID: ImageView for different sizes
问题描述
我是android studio的新手;因此,如果查询比较琐碎,请原谅.我的问题是了解布局.
I am new to android studio; so please excuse if the query is trivial. My problem is with understanding the layouts.
我的布局和相应的values文件夹如下所示.我的问题是没有选择正确的布局.例如,对于Nexus 4(4.7英寸,768x1280,xhdpi),在横向模式下,布局是从布局"文件夹中提取的.根据我的理解(可能是完全错误的:)),它应该是从layout-sw720dp-xhdpi中挑选出来的.有什么建议吗?
My layout and the corresponding values folder is as shown below. My problem is that a correct layout is not being picked up. For example, for Nexus 4 (4.7inch, 768x1280, xhdpi), in the landscape mode, the layout is being picked up from the 'layout' folder. As per my understanding (which might be totally wrong :) ) it should have been picked from layout-sw720dp-xhdpi. Any suggestions please?
推荐答案
sw 表示最小宽度.因此,如果该设备在纵向模式下的宽度为320dp,在横向模式下的宽度为720dp,那么您结束该设备的最小宽度为320dp.
sw stands for smallest width. So if the a device has a width of 320dp in portrait mode and 720dp in landscape mode then you end the device's smallest width is 320dp.
尝试使用layout-w720dp-xhdpi而不是layout-sw720dp-xhdpi,看看它是否有效.
Try use layout-w720dp-xhdpi instead of layout-sw720dp-xhdpi and see if it works.
如何在 dp
How to calculate device dimensions in dp
- 计算设备的PPI(每英寸像素数).
- 使用dp计算设备的尺寸
其中:
- =屏幕宽度(以像素为单位)
- =屏幕高度(以像素为单位)
- =屏幕对角线(以像素为单位)
- =每英寸像素数
- =屏幕对角线(以英寸为单位)
- Calculate the PPI (Pixel per inch) of the device.
- Calculate the dimensions of the device using dp
Where:
- = Screen width in pixels
- = Screen height in pixels
- = Screen diagonal in pixels
- = Pixels per inch
- = Screen diagonal in inches
根据 Wikipedia "Nexus 7(2013)屏幕现在具有1920×1200像素分辨率(960dp×600dp)".所以它的最小宽度是600dp,这就是为什么不使用您的布局的原因.
证明
PPI =(√(1920 2 + 1200 2 )))/7.02 = 322.53
dp宽度=(1920 * 160)/322.53 = 952.47 = 大约960dp
dp高度=(1920 * 160)/322.53 = 595.29 = 大约600dp
According to Wikipedia "The Nexus 7 (2013) screen now has a 1920×1200 pixel resolution (960dp × 600dp)". So its smallest width is 600dp which is why your layout isn't being used.
Proof
PPI = (√(19202 + 12002))/7.02 = 322.53
Width in dp = (1920*160)/322.53 = 952.47 = Roughly 960dp
Height in dp = (1920*160)/322.53 = 595.29 = Roughly 600dp
这篇关于ANDROID:适用于不同尺寸的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!