如何裁剪我的ImageView并按比例缩放它?

如何裁剪我的ImageView并按比例缩放它?

问题描述:

我已经尝试了几件事情,但是我的图片总是显示为按比例缩小的版本。我希望它占用全部可用的宽度,并使其在高度方向上越过图像边界。如何裁剪我的ImageView并按比例缩放它?

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/messageImageLayout" 
       android:layout_width="match_parent" 
       android:layout_height="150dp" 
       android:gravity="center_horizontal|center_vertical"> 

       <ImageView 
        android:id="@+id/messageImage" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:scaleType="fitXY" 
        android:layout_gravity="center_horizontal" 
        android:layout_marginBottom="5dp" 
        android:layout_marginTop="10dp" 
        android:adjustViewBounds="true" 
        android:src="@drawable/test" 
        android:visibility="gone" /> 

      </LinearLayout> 

现在怎么看起来:

enter image description here

我想要什么:

enter image description here

更换android:scaleType="fitXY"android:scaleType="centerCrop"代替