Anfroid 在界面中显示图片 ImageView

ImageView
1.什么是ImageView
是显示图片的一个控件
2.ImageView属性
android:src ImageView的内容颜色 
android:background ImageView背景图片
android:color ImageView的RGB颜色


项目里我新建了一个Icon,名为ic_lena。
这个项目用于演示ImageView的src属性和bakground的区别。
src和background属性可以同时存在。

ImageView部分的代码片段:

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_lena" 
        android:background="#00FFFF"
        />
<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"
    >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_lena" 
        android:background="#00FFFF"
        />
    
    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/ic_lena" />
    
    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="#00FFFF" />

    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:background="@drawable/ic_lena" />
    
</LinearLayout>
fragment_main.xml

不同分辨率下图片的显示:

ic_lena图片:

效果:

原文地址:https://www.cnblogs.com/moonlightpoet/p/5399226.html