【问题标题】:ImageView to fit height, auto scale width, keep aspect ratioImageView 适合高度,自动缩放宽度,保持纵横比
【发布时间】:2016-04-01 21:23:48
【问题描述】:

我有这样的布局:

<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) 并自动调整宽度(同时保持其纵横比),但是,它看起来像这样被拉伸:

我该如何解决这个问题?

【问题讨论】:

  • 我认为你的代码还可以,你的ImageView实际上尊重它的比例。
  • 这对我一点帮助都没有。

标签: android android-layout android-imageview android-xml


【解决方案1】:

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

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

希望对你有所帮助

【讨论】:

  • 我的布局中已经有adjustViewBoundscenterCrop 没有改变任何东西。
猜你喜欢
  • 1970-01-01
  • 2016-01-17
  • 2016-05-18
  • 2013-08-07
  • 1970-01-01
  • 1970-01-01
  • 2012-06-05
  • 1970-01-01
  • 2014-07-01
相关资源
最近更新 更多