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

6

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>

我要将ImageView的高度调整为(20dp)并自动调整宽度(同时保持其宽高比),但是它看起来像这样被拉伸了:

screenshot

该如何修复?


我认为您的代码很好,您的 ImageView 实际上遵守了其比例。 - mr.icetea
那对我完全没有帮助。 - user5721807
这个回答是否解决了你的问题?如何在 ImageView 中按比例缩放图像 - Roshana Pitigala
1个回答

0

为了保持图片比例,需要给你的 ImageView 添加两个属性:(android:adjustViewBoundsandroid:scaleType=)

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

希望这可以帮到你。

4
我的布局中已经有了adjustViewBoundscenterCrop并没有改变任何内容。 - user5721807

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接