drawable 的 intrinsicWidth ,intrinsicHeight 与分辨率

参考:图片大小与分辨率的研究

intrinsic 英 [ɪnˈtrɪnzɪk]
美 [ɪnˈtrɪnzɪk]
adj. 固有的; 内在的; 本身的

intrin-sic

Drawable

intrinsicWidth ,intrinsicHeight 为drawable属性

public abstract class Drawable {

    /**
     * Returns the drawable's intrinsic width.
     * <p>
     * Intrinsic width is the width at which the drawable would like to be laid
     * out, including any inherent padding. If the drawable has no intrinsic
     * width, such as a solid color, this method returns -1.
     *
     * @return the intrinsic width, or -1 if no intrinsic width
     */
    public int getIntrinsicWidth() {
        return -1;
    }

    /**
     * Returns the drawable's intrinsic height.
     * <p>
     * Intrinsic height is the height at which the drawable would like to be
     * laid out, including any inherent padding. If the drawable has no
     * intrinsic height, such as a solid color, this method returns -1.
     *
     * @return the intrinsic height, or -1 if no intrinsic height
     */
    public int getIntrinsicHeight() {
        return -1;
    }
}

测试


    <ImageView
        android:id="@+id/iv"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@color/colorAccent"
        android:contentDescription="简单的图片"
        android:src="@mipmap/guide" />

    <ImageView
        android:id="@+id/iv2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@color/colorAccent"
        android:contentDescription="加了padding"
        android:padding="10dp"
        android:src="@mipmap/guide" />

    <ImageView
        android:id="@+id/iv3"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@color/colorAccent"
        android:contentDescription="scaleType : fitXY"
        android:scaleType="fitXY"
        android:src="@mipmap/guide" />

    <ImageView
        android:id="@+id/iv4"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_margin="10dp"
        android:background="@color/colorAccent"
        android:contentDescription="加了margin"
        android:src="@mipmap/guide" />
  • ic_launcher.png
xxxhdpi xxhdpi xhdpi hdpi mdpi
宽/高(px) 192 144 96 72 48
比例 4 3 2 1.5 1
  • 测试手机屏幕

密度: 320dp / xhdpi / 2.0x

屏幕分辨率:720 * 1440px

  • 测试图片

宽640px * 高1136px

所有的width/height/measuredWidth/measuredHeight获取都为200(px = 100dp * 2),仅与view布局宽高和手机分辨率有关。

intrinsicWidth,intrinsicHeight:与图片原始宽高,图片放置文件夹和手机分辨率有关。

xxxhdpi xxhdpi xhdpi hdpi mdpi
比例 0.5 0.67 1 1.3 2

宽640px * 高1136px 的图片 放在mipmap-xxxhdpi

==================第一个  intrinsicWidth: 320
==================第一个  intrinsicHeight: 568
==================第2个  intrinsicWidth: 320
==================第2个  intrinsicHeight: 568
==================第③个  intrinsicWidth: 320
==================第③个  intrinsicHeight: 568
==================第肆个  intrinsicWidth: 320
==================第肆个  intrinsicHeight: 568

宽640px * 高1136px 的图片 放在mipmap-xxhdpi

==================第一个  intrinsicWidth: 427
==================第一个  intrinsicHeight: 757
==================第2个  intrinsicWidth: 427
==================第2个  intrinsicHeight: 757
==================第③个  intrinsicWidth: 427
==================第③个  intrinsicHeight: 757
==================第肆个  intrinsicWidth: 427
==================第肆个  intrinsicHeight: 757

宽640px * 高1136px 的图片 放在mipmap-xhdpi

==================第一个  intrinsicWidth: 640
==================第一个  intrinsicHeight: 1136
==================第2个  intrinsicWidth: 640
==================第2个  intrinsicHeight: 1136
==================第③个  intrinsicWidth: 640
==================第③个  intrinsicHeight: 1136
==================第肆个  intrinsicWidth: 640
==================第肆个  intrinsicHeight: 1136

宽640px * 高1136px 的图片 放在mipmap-hdpi


==================第一个  intrinsicWidth: 853
==================第一个  intrinsicHeight: 1515
==================第2个  intrinsicWidth: 853
==================第2个  intrinsicHeight: 1515
==================第③个  intrinsicWidth: 853
==================第③个  intrinsicHeight: 1515
==================第肆个  intrinsicWidth: 853
==================第肆个  intrinsicHeight: 1515

宽640px * 高1136px 的图片 放在mipmap-mdpi

==================第一个  intrinsicWidth: 1280
==================第一个  intrinsicHeight: 2272
==================第2个  intrinsicWidth: 1280
==================第2个  intrinsicHeight: 2272
==================第③个  intrinsicWidth: 1280
==================第③个  intrinsicHeight: 2272
==================第肆个  intrinsicWidth: 1280
==================第肆个  intrinsicHeight: 2272

发布了767 篇原创文章 · 获赞 204 · 访问量 92万+

猜你喜欢

转载自blog.csdn.net/sinat_31057219/article/details/104798364
今日推荐