ImageView的adjustViewBounds属性再解读

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




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值