Android中mipmap和drawable文件夹的区别

本文介绍了Android中mipmap和drawable资源文件夹的不同用途。mipmap主要用于存放应用启动图标,确保图标能在不同屏幕密度下保持清晰;drawable则用于存放其他位图资源如图片和9-patch图像等。

Google官方关于mipmapdrawable的介绍

drawable/

For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). See the Drawable resource type.

mipmap/

For app launcher icons. The Android system retains the resources in this folder (and density-specific folders such as mipmap-xxxhdpi) regardless of the screen resolution of the device where your app is installed. This behavior allows launcher apps to pick the best resolution icon for your app to display on the home screen. For more information about using the mipmap folders, see Managing Launcher Icons as mipmap Resources.

drawable:位图文件(.png.9.png.jpg.gif)或编译为以下可绘制对象资源子类型的XML文件(位图文件、九宫格(可调整大小的位图)、状态列表、形状、动画可绘制对象、其他可绘制对象)。

mipmap:适用于不同启动器图标密度的可绘制对象文件。

StackOverflow上关于mipmapdrawable的区别

The mipmap folders are for placing your app icons in only. Any other drawable assets you use should be placed in the relevant drawable folders as before.

综上mipmap文件夹适合放应用启动图标,而其他图片资源应该放在drawable文件夹下面。

It’s best practice to place your app icons in mipmap- folders (not the drawable- folders) because they are used at resolutions different from the device’s current density.

Android Studio中,不同的`drawable`文件夹主要用于适配不同屏幕密度的设备。常见的`drawable`文件夹有`drawable-hdpi`、`drawable-mdpi`、`drawable-xhdpi`、`drawable-xxhdpi`等。当应用运行在不同屏幕密度的设备上时,系统会自动从相应的`drawable`文件夹中选择合适的图片资源,以保证图片在不同设备上都能以合适的大小清晰度显示。 - **`drawable-mdpi`**:适用于中等密度屏幕(约160dpi)的设备。在这个文件夹中放置的图片会在中等密度屏幕上以原始大小显示。如果在其他密度的屏幕上使用这些图片,系统会自动进行缩放,可能会导致图片模糊或失真。 - **`drawable-hdpi`**:适用于高密度屏幕(约240dpi)的设备。这里的图片比`drawable-mdpi`中的图片要大,在高密度屏幕上可以显示得更加清晰。当应用运行在高密度屏幕设备上时,系统会优先从这个文件夹中加载图片。 - **`drawable-xhdpi`**:适用于超高密度屏幕(约320dpi)的设备。该文件夹中的图片更大,以适应更高的屏幕分辨率。在超高密度屏幕上使用这些图片可以避免因缩放而导致的画质损失。 - **`drawable-xxhdpi`**:适用于超超高密度屏幕(约480dpi)的设备。这里的图片尺寸更大,能在超超高密度屏幕上提供最佳的显示效果。 例如,如果一个应用在`drawable-mdpi`、`drawable-hdpi`、`drawable-xhdpi``drawable-xxhdpi`文件夹中都放置了同一张图片的不同尺寸版本,当应用运行在一个超高密度屏幕(约320dpi)的设备上时,系统会优先从`drawable-xhdpi`文件夹中加载图片,以保证图片的清晰度质量。 在Nexus 6这类设备上,其屏幕像素密度(PPI)为493,介于`xxhdpi``xxxhdpi`之间,显示时需要对`xxxhdpi`的资源进行缩小。若使用了`mipmap-xxxhdpi`,会对缩放有优化,性能更好且占用内存更少,所以官方推荐使用`mipmap`来存放图片 [^5]。 ```xml <!-- 在布局文件中引用图片资源 --> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/my_image" /> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值