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图片时,会压缩上述图片。

  • 相关阅读:
    ECSHOP 2.5.1 二次开发文档【文件结构说明和数据库表分析】
    ECSHOP后台左侧添加菜单栏
    PHPstudy 2018 集成环境项目配置虚拟域名访问
    微擎左侧模块业务菜单修改
    ThinkPHP5使用阿里云OSS图片上传
    ThinkPHP5使用PHPExcel实现数据导出功能
    ThinkPHP5生成二维码图片与另一张背景图片进行合成
    原生PHP连接MySQL数据库
    数组的冒泡排序
    【原创诗歌】读仓央嘉措(下)
  • 原文地址:https://www.cnblogs.com/CVstyle/p/6399255.html
Copyright © 2011-2022 走看看