ANDROID: ImageView for different sizes

2019-02-26 02:29发布

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

1条回答
对你真心纯属浪费
2楼-- · 2019-02-26 03:10

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.
    enter image description here
    enter image description here
  2. Calculate the dimensions of the device using dp
    enter image description here
    enter image description here
    Where:
    • enter image description here = Screen width in pixels
    • enter image description here = Screen height in pixels
    • enter image description here = Screen diagonal in pixels
    • enter image description here = Pixels per inch
    • enter image description here = 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

查看更多
登录 后发表回答