简体   繁体   English

Android图片可在不同屏幕尺寸下正确缩放

[英]Android images to scale properly in different screen sizes

I'm new to Android and I'd like to know why those images I put in hdpi , ldpi , mdpi , xhdpi folders are not actually responding to what I want. 我是Android的新手,我想知道为什么我放在hdpildpimdpixhdpi文件夹中的那些图像实际上没有响应我想要的内容。

In hdpi , I put images that are fit for big screens. hdpi中 ,我放置了适合大屏幕的图像。

In ldpi , for small screens, in mdpi for normal screens and for xhdpi for tablets. ldpi中 ,对于小屏幕,在mdpi中,对于常规屏幕,对于xhdpi,对于平板电脑。

But I wonder why it's still not displaying the correct images for big screens. 但是我想知道为什么它仍然不能在大屏幕上显示正确的图像。 It looks like small images (that are fit for small screens) on the screen. 它看起来像屏幕上的小图像(适合小屏幕)。 I have named the images exactly the same. 我已命名图像完全相同。 What is wrong with this? 这有什么问题?

I need your suggestion. 我需要你的建议。 Help is much appreciated. 非常感谢您的帮助。 Thanks in advance. 提前致谢。

I think that you don't have the problem in the code, nor in the images, but in the devices you're using to try the different densities. 我认为您在代码或图像中都没有问题,但是在您尝试不同密度的设备中没有问题。 If you are assuming that larger screens means higher densities, that is not always the case. 如果您假设更大的屏幕意味着更高的密度,那么情况并非总是如此。 Note that hdpi , ldpi , mdpi and xhdpi refer to density , not screen size. 请注意, hdpildpimdpixhdpi指的是密度 ,而不是屏幕尺寸。

For example, below you can find two screenshots of the same ImageView pointing to the same @drawable/a icon but deployed in two devices with different screen density . 例如,下面您可以找到同一ImageView两个屏幕快照,它们指向相同的@drawable/a图标,但部署在具有不同屏幕密度的两个设备中。 To make the point I have placed completely different icons (both with the same name a.png ) in each density folder so that the difference can be easily appreciated: 为了说明这一点,我在每个密度文件夹中放置了完全不同的图标(都具有相同的名称a.png ),以便可以轻松理解其中的区别:

2.7" - ldpi 2.7英寸-ldpi 2.7英寸-ldpi 3.7" - hdpi 3.7英寸-hdpi 3.7英寸-hdpi

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

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