ANDROID:不同尺寸的 ImageView [英] ANDROID: ImageView for different sizes

查看:34
本文介绍了ANDROID:不同尺寸的 ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 android studio 的新手;所以请原谅,如果查询是微不足道的.我的问题是理解布局.

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




  • 哪里:
    • = 屏幕宽度(以像素为单位)
    • = 屏幕高度(以像素为单位)
    • = 以像素为单位的屏幕对角线
    • = 每英寸像素数
    • = 以英寸为单位的屏幕对角线


  • 根据维基百科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

    I am new to android studio; so please excuse if the query is trivial. My problem is with understanding the layouts.

    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?

    layout-problem

    解决方案

    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.

    Try use layout-w720dp-xhdpi instead of layout-sw720dp-xhdpi and see if it works.

    How to calculate device dimensions in dp

    1. Calculate the PPI (Pixel per inch) of the device.

    2. 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


    Edit:
    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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆