做Android有段时间了,但是好多细节还没有深入理解,关于Android中drawable文件夹的使用理解的就不是很深入。

Android为开发者提供了两种解决适配问题的方法,第一种方式是使用dip的单位,另一种方法是使用不同的drawable文件夹,今天就详细说下不同文件夹的区别

Android中提供了三个存放图片的文件夹,分别为hdpi,mdpi,ldpi,google文档上说,Andriod系统会根据手机屏幕的大小及屏幕密度去选择不同文件夹下的图片资源,以此来实现在不同大小不同屏幕分辨率下适配的问题。

比如在一个低分辨率的手机上,Android就会选择ldpi文件夹下的图片,但是如果没有在ldpi的文件夹下找见相关的资源文件,Android系统会首先从hdpi文件夹中选择文件,然后对图片资源进行缩放处理,显示在屏幕上;如果hdpi文件夹下也没有的话,会在默认的drawable文件夹中寻找。

明白以上内容,就很好解释图片放错文件夹,显示大小不同的问题了。如图

图1

图2

出现图二的原因是将放在hdpi下的图片放到了默认的文件夹下

本身图片是同一张图片,由于没有在hdpi文件夹中找到对应图片,系统在默认文件夹下找见了图片资源,但是这时系统会认为改图适用于中等分辨率的屏幕上,如果直接放到高分辨率的手机上不能适配,所以系统会自动的将图片放大,所以虽然是同一张图片,但是现实出来就一个正常效果,一个放大效果。

同理,如果同一张图片,放置在ldpi的文件夹下,在低分辨率的手机上显示正常,但是如果放在hdpi文件夹中,系统认为该图是为高分辨率显示的,要将图片缩小处理,所以显示出来的效果就是图变小了。

所以我们在平时要注意,明明都是一张图片,只是放在不同的文件夹中,显示出来的效果就很不同,原因就是我们对Android还不够了解。

对了,我还有个疑问,就是布局文件中设置wrap_content时,view的大小的单位是dip还是px呢!!!

以下为google文档的描述

At runtime, the system ensures the best possible display on the current screen with the following procedure for any given resource:

  1. The system uses the appropriate alternative resource

    Based on the size and density of the current screen, the system uses any size- and density-specific resource provided in your application. For example, if the device has a high-density screen and the application requests a drawable resource, the system looks for a drawable resource directory that best matches the device configuration. Depending on the other alternative resources available, a resource directory with thehdpi qualifier (such as drawable-hdpi/) might be the best match, so the system uses the drawable resource from this directory.

  2. If no matching resource is available, the system uses the default resource and scales it up or down as needed to match the current screen size and density

    The "default" resources are those that are not tagged with a configuration qualifier. For example, the resources in drawable/ are the default drawable resources. The system assumes that default resources are designed for the baseline screen size and density, which is a normal screen size and a medium density. As such, the system scales default density resources up for high-density screens and down for low-density screens, as appropriate.

    However, when the system is looking for a density-specific resource and does not find it in the density-specific directory, it won't always use the default resources. The system may instead use one of the other density-specific resources in order to provide better results when scaling. For example, when looking for a low-density resource and it is not available, the system prefers to scale-down the high-density version of the resource, because the system can easily scale a high-density resource down to low-density by a factor of 0.5, with fewer artifacts, compared to scaling a medium-density resource by a factor of 0.75.

from:http://blog.csdn.net/peidonghui/article/details/8508171

【转】Android总结之drawable(hdpi,mdpi,ldpi)文件夹的使用的更多相关文章

  1. (转)关于Android的nodpi,xhdpi,hdpi,mdpi,ldpi

    首先是几个基本概念:1.屏幕尺寸Screen size即显示屏幕的实际大小,按照屏幕的对角线进行测量.为简单起见,Android把所有的屏幕大小分为四种尺寸:小,普通,大,超大(分别对应:small, ...

  2. 图标:适配不同分辨 的 hdpi、mdpi、ldpi 文件夹

    一:不同的layout Android手机屏幕大小不一,有480×320, 640×360, 800×480.怎样才能让App自动适应不同的屏幕呢? 其实很简单,只需要在res目录下创建不同的layo ...

  3. Android加载SD卡目录,文件夹遍历,图片设置,设置文件对应打开方式等

    此案例主要说的是Android使用GridView加载SD卡下所有目录,文件夹多层遍历,文件图标修改,设置文件对应打开方式等功能. 如图: 代码: public class GridViewFile ...

  4. 如何在Android Studio中创建jniLib和asset文件夹 2

    1.创建asset文件夹 如图进行操作 2.创建jniLib文件夹 —打开app下面的gradle文件(不是project的gradle) —在gradle文件的Android标签里面添加 sourc ...

  5. Android中res下anim和animator文件夹区别与总结

    1.anim文件夹 anim文件夹下存放tween animation(补间动画)和frame animation(逐帧动画) 逐帧动画: ①在animation-list中使用item定义动画的全部 ...

  6. Android播播放完SD卡指定文件夹音乐之后,自动播放下一首

    最近做一个项目,需要连续播放音乐,播放完一首歌之后,自动播放完下一首歌.不要重复播放. 代码如下: package com.example.asyncplayer_ex; import java.io ...

  7. android中保存Bitmap图片到指定文件夹中的方法

    /** 保存方法 */  public void saveBitmap() {   Log.e(TAG, "保存图片");   File f = new File("/s ...

  8. 为什么很多 Android 程序喜欢在存储卡根目录建文件夹来存储数据而不是 Android/data 目录下?

    知乎回答.   http://www.zhihu.com/question/19866689   pansz,欢迎评论 知乎用户.弓长.知乎用户 赞同 这个道理很简单:因为没人管啊.你乱存放文件,在a ...

  9. Android studio移动项目到另外一个文件夹,结果不能安装的解决方法

    删除.gradle , .idea , build 三个文件夹即可

随机推荐

  1. oracle 备份恢复篇(四)---rman 单个数据文件

    一,环境背景

  2. oracle 操作实例(一)----redolog 损坏恢复

    一,实验前的准备 数据库全备保证自己没成功还能补救一下 vim full.sh export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=$ORACL ...

  3. shell 函数与内置变量

    1,特殊shell变量 $# 传递到脚本的参数个数 $* 以一个单字符串显示所有向脚本传递的参数 $$ 脚本运行的当前进程ID号 $! 后台运行的最后一个进程的ID号 $@ 与$*相同,但是使用时加引 ...

  4. Java - > for, while 及 do.while循环

    为什么要用到循环结构: 按顺序结构执行程序语句(方法或者代码块)只能被执行一次.如果要多次执行,就需要使用到循环结构(循环结构是指在程序中需要反复执行某个功能而设置的一种程序结构) 布尔表达式:是一段 ...

  5. mysql 语句学习一 关于系统信息的查询

    首先说一下,SQL语句是不区分大小写的. 1.SELECT VERSION();           -- 查询当前版本号 2.SELECT CURRENT_TIME(); -- 查询当前时间 3.S ...

  6. 集合异常之List接口

    List接口介绍:是Collection接口中的子类, 特点: l  它是一个元素存取有序的集合.例如,存元素的顺序是11.22.33.那么集合中,元素的存储就是按照11.22.33的顺序完成的).( ...

  7. jQuery基础——选择器、效果

    一.使用JS的痛处 在学习和使用js的过程中发现了js的一些痛处: 1.书写繁琐,代码量大. 2.代码复杂. 3.动画效果很难实现.使用定时器,要小心各种定时器的清除.各种操作和处理事件不好实现. 4 ...

  8. 前端如何使用proxyTable和nginx解决跨域问题

    最近经常遇到跨域的问题,有时候问题虽然解决了,但是还是会有些模棱两可概念不清,于是在网上看了一些教程结合实际使用,做个笔记. 1.跨域原因 浏览器的限制 跨域(协议/域名/端口的不同) XMLHttp ...

  9. js动画杂记

    在画布上做动画 方法有 setIntervel(function(){},time); setTimeout(function(){},time); 新方法 window.requestAnimati ...

  10. 【代码笔记】Java连连看项目的实现(2)——JTable 、TableModel的使用

    博客有时间就写写,所以一篇可能会拆成很多篇,写完后计划再合在一起. 首先肯定是要实现连连看的界面. 先准备连连看要的图片.. “LianLianKan”就是项目名称. 当然,如果小白看我的博客想学到什 ...