------ adjustViewBounds屬性要求api level 不小於18
If the application targets API level 17 or lower, adjustViewBounds will allow the drawable to shrink the view bounds,
but not grow to fill available measured space in all cases.
This is for compatibility with legacy MeasureSpec and RelativeLayout behavior.
------- 代碼
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gaos.viewanimation.MainActivity">
<ImageView
android:id="@+id/imgview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/superman" />
</RelativeLayout>
----------- 當我不限制ImageView的高度時
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.gaos.viewanimation.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imgview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/superman" />
</ScrollView>
</RelativeLayout>