android - ANDROID:适用于不同尺寸的ImageView

标签 android android-layout android-studio layout

我是android studio的新手;因此,如果查询比较琐碎,请原谅。我的问题是了解布局。

我的布局和相应的values文件夹如下所示。我的问题是没有选择正确的布局。例如,对于Nexus 4(4.7英寸,768x1280,xhdpi),在横向模式下,布局是从“布局”文件夹中提取的。根据我的理解(可能是完全错误的:)),它应该是从layout-sw720dp-xhdpi中选择的。有什么建议吗?

layout-problem

最佳答案

sw代表最小宽度。因此,如果该设备在纵向模式下的宽度为320dp,在横向模式下的宽度为720dp,则结束时设备的最小宽度为320dp。

尝试使用layout-w720dp-xhdpi而不是layout-sw720dp-xhdpi,看看它是否有效。

如何在dp中计算设备尺寸


Calculate the PPI (Pixel per inch) of the device.
enter image description here
enter image description here
Calculate the dimensions of the device using dp
enter image description here
enter image description here
哪里:


enter image description here =屏幕宽度(以像素为单位)
enter image description here =屏幕高度(以像素为单位)
enter image description here =屏幕对角线,以像素为单位
enter image description here =每英寸像素
enter image description here =屏幕对角线,以英寸为单位




编辑:根据Wikipedia“ Nexus 7(2013)屏幕现在具有1920×1200像素分辨率(960dp×600dp)”。因此其最小宽度为600dp,这就是为什么不使用布局的原因。
证明
PPI =(√(19202 + 12002))/ 7.02 = 322.53
dp宽度=(1920 * 160)/322.53 = 952.47 =约960dp
以dp为单位的高度=(1920 * 160)/322.53 = 595.29 =大约600dp

关于android - ANDROID:适用于不同尺寸的ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36834113/

相关文章:

android-layout - 来自 View 适配器的无条件布局膨胀。 Kotlin

Android Studio 2.0 定位系统镜像不一致

成功构建和安装 apk 后,Android Studio 应用程序在运行时崩溃

android - 如何在 Android Studio 的编辑器中添加字体

android - 用 KitKat 的灰色色调覆盖 Android 的蓝色色调的最简单方法是什么?

android - 监听 Tab/Android 中的 Switch 状态变化

android - 如何将openssl生成的RSA私钥导入AndroidKeyStore

java - 没有这样的表 : goods:

Android:滚动到 View 底部

android - 地理围栏不触发