ImageView主要是用来显示图片的控件,可以对图片进行发大、缩小和旋转的功能。android:scaleType属性指定ImageView控件显示图片的方式,例如:Center表示图像以不缩放的方式显示在ImageView控件的中心,如果设置为fitCenter,表示图像按照比例缩放至合适的位置,并在ImageView控件的中心。

下面介绍ImageView的基本用法。

一、建立工程,如图

ImageView显示图像控件(基本用法)ImageView显示图像控件(基本用法)

二、activity_main.xml中代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro>
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:text="scaleType:center 为缩放,放在ImageView的中心" 
        />
    <ImageView android:> 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:background="#F00"
        android:src="@drawable/background" 
        android:scaleType="center">
    </ImageView>

    <TextView android:layout_width="fill_parent"
        android:layout_marginTop="20dp" 
        android:layout_height="wrap_content"
        android:text="scaleType:fitCenter 按照比例缩放" />

    <ImageView android:> 
        android:layout_width="300dp"
        android:layout_height="200dp" 
        android:background="#FFF"
        android:src="@drawable/background" 
        android:scaleType="fitCenter"
        android:padding="10dp">
    </ImageView>
</LinearLayout>
View Code

相关文章: