简体   繁体   English

如何知道 Android 中所有屏幕密度的像素范围? (图像的基本浓度)

[英]How can I know the pixels range for all screen densities in Android ? (base density of an image)

So imagine that I have an image that is 700x700 px in res folder and I want my app to support different pixel densities.所以想象一下,我在 res 文件夹中有一个 700x700 像素的图像,我希望我的应用程序支持不同的像素密度。 So according to the documentation:所以根据文档:

ldpi -- 0.75x低密度脂蛋白——0.75x
mdpi -- 1x mdpi -- 1x
hdpi -- 1.5x hdpi -- 1.5x
xhdpi -- 2.0x xhdpi -- 2.0x
xxhdpi -- 3.0x xxhdpi -- 3.0x
xxxhdpi -- 4.0x xxxhdpi -- 4.0x

So now, my question is, if my image is 700x700 px, I can think that those 700x700px are the resolution of 1x (mdpi), so the resolutions for the different densities would be the following:所以现在,我的问题是,如果我的图像是 700x700 像素,我可以认为那些 700x700 像素是 1x (mdpi) 的分辨率,所以不同密度的分辨率如下:

ldpi -- 525x525px ldpi -- 525x525px
mdpi -- 700x700px mdpi -- 700x700px
hdpi -- 1050x1050px hdpi -- 1050x1050px
xhdpi -- 1400x1400px xhdpi -- 1400x1400px
xxhdpi -- 2100x2100px xxhdpi -- 2100x2100px
xxxhdpi -- 2800x2800px xxxhdpi -- 2800x2800px

But also I can think that my 700x700 image that I have is for the biggest density, so it is the 4.0x (xxxhdpi), so the resolutions for the different densities would be the following:但我也可以认为我拥有的 700x700 图像是最大密度的,所以它是 4.0x (xxxhdpi),所以不同密度的分辨率如下:

ldpi -- 131.25x131.25px ldpi -- 131.25x131.25px
mdpi -- 175x175px mdpi -- 175x175px
hdpi -- 262.5x262.5px hdpi -- 262.5x262.5px
xhdpi -- 350x350px xhdpi -- 350x350px
xxhdpi -- 525x525px xxhdpi -- 525x525px
xxxhdpi -- 700x700px xxxhdpi -- 700x700px

But also, I can think that those 700x700px are for ldpi,hdpi,xhdpi,xxhdpi, so there are there are six different possible combinations... I would like to know which of all should be the density base of my 700x700 px image.而且,我可以认为那些 700x700px 用于 ldpi、hdpi、xhdpi、xxhdpi,所以有六种不同的可能组合......我想知道哪一个应该是我的 700x700 px 图像的密度基础。 I think that maybe knowing a pixel range table of all the densities that shows the minimum and maximum pixels for each density would be really helpful.我认为也许知道显示每个密度的最小和最大像素的所有密度的像素范围表会非常有帮助。

You could count these values using methods like:您可以使用以下方法计算这些值:

my solution is to get any layout form your .xml by id and just count it using the same methods我的解决方案是通过 id 从您的.xml中获取任何布局,然后使用相同的方法对其进行计数

layout.width
layout.height

or或者

        // on below line we are creating and
        // initializing variable for display metrics.
        val displayMetrics = DisplayMetrics()
 
        // on below line we are getting metrics
        // for display using window manager.
        windowManager.defaultDisplay.getMetrics(displayMetrics)
 
        // on below line we are getting height
        // and width using display metrics.
        val height = displayMetrics.heightPixels
        val width = displayMetrics.widthPixels

Also if you want to handle showing images on UI just use Glide Library此外,如果您想处理在 UI 上显示图像,只需使用Glide Library

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

相关问题 我需要知道屏幕尺寸和屏幕密度之间有什么区别 - i need to know what different between screen size and screen density 如何正确将地理坐标转换为屏幕上的像素? - How can I correctly convert geographical coordinates to pixels on screen? FindViewById和不同屏幕密度的多种布局(Android) - FindViewById and multiple layouts for different screen densities (Android) Android兼容屏幕和密度 - Android compatible screen and density 我应该在哪里关注所有100%的移动设备和平板电脑而忽略其屏幕尺寸或密度? - where should i focus on to support all 100% mobiles and tablets ignoring whatever their screen sizes or densities? 有谁知道如何自动找到手机屏幕上的坏点? - Does anyone know how to find dead pixels on a phone screen automatically? 如何加载位图图像并操纵单个像素? - How can I load a bitmap image and manipulate individual pixels? 如何从 java 中的像素值数组显示图像? - How can I display an image from an array of pixels' values in java? 如何在不同的屏幕尺寸和密度下使 TextView 中的文本大小保持一致? - How do I keep Text Size in TextView consistent over different screen sizes and densities? 如何找到图像视图上触摸的所有像素? - How to find all pixels touched on an image view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM