0

So imagine that I have an image that is 700x700 px in res folder and I want my app to support different pixel densities. So according to the documentation:

ldpi -- 0.75x
mdpi -- 1x
hdpi -- 1.5x
xhdpi -- 2.0x
xxhdpi -- 3.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:

ldpi -- 525x525px
mdpi -- 700x700px
hdpi -- 1050x1050px
xhdpi -- 1400x1400px
xxhdpi -- 2100x2100px
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:

ldpi -- 131.25x131.25px
mdpi -- 175x175px
hdpi -- 262.5x262.5px
xhdpi -- 350x350px
xxhdpi -- 525x525px
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. 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.

1 Answers1

0

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

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

Vidar567
  • 130
  • 8