【问题标题】:Going crazy with scaleType用 scaleType 发疯
【发布时间】:2014-10-22 23:25:58
【问题描述】:

我的图片可以是 300x600 像素或 600x300 像素。我希望它们显示在一个 50dp 的框中。所以图像将是 25dp x 50dp 或 50x25dp,具体取决于其比例

我尝试了各种方法,我快要疯了

<RelativeLayout
    android:layout_width="50dp"
    android:layout_height="50dp">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/image"/>
</RelativeLayout>

(这不会裁剪任何东西......)

    <ImageView
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:scaleType="centerCrop"
        android:adjustViewBounds="true"
        android:background="@drawable/image"/>

但是没有任何作用,似乎我在scaleType 中输入的任何值都被忽略了

【问题讨论】:

  • 看看this是否有效
  • 所以你不能通过xml做到这一点?

标签: android android-layout


【解决方案1】:

使用scaleType="fitCenter"(如果您想放大小图像)或scaleType="centerInside"(否则)。

禁用adjustViewBounds

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-30
    • 2012-11-02
    • 2020-11-13
    • 1970-01-01
    相关资源
    最近更新 更多