ImageView的adjustViewBounds属性再解读

来源:互联网 发布:云计算与服务工程 编辑:程序博客网 时间:2024/06/05 04:07

------ 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>


① 当不限制ImageView的高度,在原图宽高比为700:1120的情况下,图片宽度匹配了ImageView的最大宽度,高度不限制,所以adjustViewBounds属性实现了图片的宽度match_parent




0 0