ImageView是一个可以显示任何图片资源的控件,同时可以调整图片的像素,显示的位置,图片的滚动等问题。
ImageView有很多常用的属性,下面会一一解释。先看布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- 按比例缩小图片以适应ImageView的大小 -->
<ImageView
android:id="@+id/img1"
android:adjustViewBounds="true" //是否按比例缩小
android:maxWidth="150dp"
android:maxHeight="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/second"
android:layout_gravity="center_horizontal"
/>
<!-- 放大/缩小图片以适应ImageView大小 -->
<Linea