Android中不同大小的图像 [英] Different sizes of images in Android

查看:204
本文介绍了Android中不同大小的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GridView在应用程序中创建主要活动.我需要一个3x3的网格.每个单元格都包含ImageView(用于不同操作的图标).所有图像必须具有相同的尺寸.我的问题是:我必须使用什么尺寸的图像?我看了教程,发现一张桌子,上面有不同分辨率和密度的尺寸.但是我不明白.例如,我的密度为mdpi,屏幕尺寸为480 * 800.这是否意味着我应该在该屏幕上使用图标160 * 266?其他密度和屏幕尺寸应该是什么尺寸?我该如何计算?

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?

推荐答案

这是最常见的问题之一,您可以搜索更多详细信息,但让我简要介绍一下它的工作原理.

This is one of the most asked question, you can search for more details, but let me give you briefly how it works.

MDPI被视为基准,其次是规模

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.

由于您要具有大小相等的像元的3X3网格,因此可以考虑以下内容.
通常,mdpi屏幕尺寸为360 X 640,因此每个图像尺寸约为120dp X 212dp.

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?

项目->应用-> src->主-> res

在这里,创建名称为drawable-mdpidrawable-hdpi等的文件夹,并将相应的图像放置在这些文件夹中.

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.

根据文档,考虑了MDPI和HDPI屏幕尺寸 它们的宽高比为3:4,但是由于大多数用户都具有高清 宽高比为9:16的设备,您可以考虑采用最标准的 市场中的屏幕尺寸,即1080 X 1920,对应于XXHDPI和 用作假设将MDPI设为360的假设 X640.对于高质量的应用程序,必须进行权衡以降低性能 设备,因为大多数现有用户具有XXHDPI或更高版本 设备.

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.

这篇关于Android中不同大小的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆