问题
I'm trying to create main activity in my application using GridView. I need to have a grid 3x3. Every cell contains ImageView (icons for different actions). All images must have the same size. And my question is: what sizes of image I must use? I watched tutorial and found a table with sizes for different resolutions and density. But I didn't understand. For instance, I have mdpi density and screen size 480*800. Does it mean that I should use icons 160*266 for this screen? And what sizes should be for other densities and screen sizes? How can I calculate them?
回答1:
This is one of the most asked question, you can search for more details, but let me give you briefly how it works.
MDPI is considered as the base line and following are the scales
MDPI - X1 HDPI - X1.5 XHDPI - X2 XXHDPI - X3 XXXHDPI - X4
Now you must be thinking what is this.
Since you want to have 3X3 grid with cell of equal size, you can consider the following.
In general mdpi screen size is 360 X 640, so each image size will be 120dp X 212dp Approx.
For mdpi screen, your Image size should be 120px X 212px For hdpi screen, your Image size should be 180px X 318px For xhdpi screen, your Image size should be 240px X 424px For xxdpi screen, your Image size should be 360px X 636px For xxxdpi screen, your Image size should be 480px X 848px
Now where you should place these images?
Project -> app -> src -> main -> res
Here, create folders with name drawable-mdpi
, drawable-hdpi
, etc, and place respective images in these folders.
Thats it for supporting multiple screen densities.
According to docs, MDPI and HDPI screen sizes are given considering their aspect ratio to 3:4, but since most of the users have HD devices with aspect ratio of 9:16, you can consider the most standard screen size in Market i.e. 1080 X 1920 which corresponds to XXHDPI and acts as baseline to make the assumption of considering MDPI to be 360 X 640. For high quality apps, trade off has to be made for lower devices since most of the existing users have XXHDPI or higher devices.
来源:https://stackoverflow.com/questions/42780062/different-sizes-of-images-in-android