ImageView适合高度,自动缩放宽度,保持纵横比

时间:2021-11-12 18:57:37

I have a layout like this:

我有这样的布局:

<LinearLayout
    android:layout_width="32dp"
    android:layout_height="32dp"
    android:layout_marginEnd="8dp"
    android:gravity="start|center_vertical"
    android:orientation="horizontal"
    android:layout_weight="0.25">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="20dp"
        android:background="@drawable/reply_icon"
        android:scaleType="fitCenter"
        android:adjustViewBounds="true"
        />

</LinearLayout>

I'm trying to get the ImageView to fit its height (20dp) and auto-adjust the width (while keeping its aspect ratio), however, it comes out looking stretched like this:

我试图让ImageView适合它的高度(20dp)并自动调整宽度(同时保持其宽高比),然而,它出来看起来像这样拉伸:

ImageView适合高度,自动缩放宽度,保持纵横比

How can I fix this?

我怎样才能解决这个问题?

1 个解决方案

#1


-1  

Add two attributes: (android:adjustViewBounds and android:scaleType=) to your ImageView for keep aspect ratio

将两个属性:(android:adjustViewBounds和android:scaleType =)添加到ImageView以保持纵横比

android:adjustViewBounds="true"
android:scaleType="centerCrop"

Hope this help

希望这有帮助

#1


-1  

Add two attributes: (android:adjustViewBounds and android:scaleType=) to your ImageView for keep aspect ratio

将两个属性:(android:adjustViewBounds和android:scaleType =)添加到ImageView以保持纵横比

android:adjustViewBounds="true"
android:scaleType="centerCrop"

Hope this help

希望这有帮助