不同dpi下图片显示的理解的demo

代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView android:layout_width="wrap_content" 
          android:text="warp_content" />
    <ImageView android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:background="@drawable/home_title_bar_bg" />
    <TextView android:layout_width="wrap_content" 
          android:layout_height="wrap_content" 
          android:text="320dip" />
    <ImageView android:layout_width="320dip" 
         android:layout_height="wrap_content" 
         android:background="@drawable/home_title_bar_bg" />
    <TextView android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="320px" />
    <ImageView android:layout_width="320px" 
       android:layout_height="wrap_content" 
        android:background="@drawable/home_title_bar_bg"  />
</LinearLayout>

 

=====================================================================

480x800dpi160 下的显示结果:

=================================================================

480x800dpi240 下的显示结果:

=================================================================

注意:上述情况是在drawable-hdpidrawable-mdpi 中都存在一张宽为320px 的图片时显示的效果。

当图片只在一个资源下时,使用wrap_parent 作为宽度,其它分辨率下的布局会先通过转换图片的大小后,再显示。

例子:只在 drawable-hdpi 中存在一张320px 宽的图片,这时在DPI160 的布局文件中,该图片显示的宽度为320*2/3

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值