zoukankan      html  css  js  c++  java
  • Android像素密度单位解析

    Android应用程序 res/drawable-hdpi drawable-xxhdpi 显示的不同

     

    对比实验:

    创建项目后,默认在相关文件目录中生成以下图标:

    hdpi --> 72px

    mdpi --> 48px

    hdpi --> 96px

    xxhdpi --> 144px

    实验一: 使用ImageView装载上述图片

    布局文件如下:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:context="com.spt.MainActivity" >
        <ImageView
            android:id="@+id/iv_image"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_blue_light" >
        </ImageView>
        <ImageView
            android:id="@+id/iv_compare"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/holo_orange_light" >
        </ImageView>
    </LinearLayout>

    实验系统现状:屏幕dpi为240

    项目现状:

    默认情况下,会使用下述尺寸显示上述图片:

    Drawable drawable = getResources().getDrawable(R.drawable.ic_launcher,
                    getTheme());
    mIv.setImageDrawable(drawable);
    mIvCompared.setImageDrawable(drawable);
    Log.d(TAG, "onResume::width=" + drawable.getMinimumWidth());
    Log.d(TAG, "onResume::height=" + drawable.getMinimumHeight());

    输出结果,如下:

    D/MainActivity( 4333): getDisplayDemension::densityDpi=240
    D/MainActivity( 4333): onResume::width=72
    D/MainActivity( 4333): onResume::height=72

    默认会在drawable-hdpi的目录中查找该ic_launcher.png图片

    实验二:对比实验,将drawable-hdpi的目录中的ic_launcher.png图片删除,保留drawable-xxhdpi目录中的图片

    系统会使用drawable-xxhdpi目录中的ic_launcher.png

    上述实验现象基本相同。

    Android系统在使用drawable-xxhdpi目录中的ic_launcher.png图片时,会压缩上述图片。

  • 相关阅读:
    程序经理_产品经理_项目经理
    github上排名靠前的java项目之_storm
    垂直型与水平型电子商务网站的理解
    关于驱动更新的一点学习
    Balanced Binary Tree
    Gray Code
    Best Time to Buy and Sell Stock II
    Best Time to Buy and Sell Stock
    Maximum Depth of Binary Tree
    Next Permutation
  • 原文地址:https://www.cnblogs.com/CVstyle/p/6399255.html
Copyright © 2011-2022 走看看