【问题标题】:maxHeight ignored on ImageView even with adjustViewBounds即使使用 adjustViewBounds,在 ImageView 上也会忽略 maxHeight
【发布时间】:2016-02-16 10:41:12
【问题描述】:

我有一个 imageView,我希望它尽可能大,限制它的高度,并保持它的纵横比,我的问题是它得到了它可以忽略我设置的 maxHeight 的整个空间。这是代码:

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:maxHeight="100dp"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_profile"/>
</LinearLayout>

为什么在adjustViewBounds 为true 时忽略maxHeight 事件?我该如何解决这个问题?

提前致谢!

【问题讨论】:

  • 尝试为 LinearLayout 设置 android:maxHeight="100dp" 并从图像视图中删除该行。
  • 试试android:scaleType="centerInside"ImageView
  • 感谢您的回答,我试过了,但没有解决问题:(

标签: android android-layout android-imageview android-image


【解决方案1】:

试试这个。这里的 textView 是您需要在屏幕上显示图像的其他内容。

 <LinearLayout
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:weightSum="2">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:maxHeight="100dp"
                android:adjustViewBounds="true"
                android:src="@drawable/logo"/>
        </LinearLayout>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:text="hello"
        />
</LinearLayout>

【讨论】:

  • 感谢您的回答。这不起作用,因为如果没有足够的空间,我希望图像变小。因此,需要重量。
  • 如果是较大的图像,则不会超过 100dp,如果是较小的图像,则会保留其原始大小。我不明白你的用例。
  • 我的问题是我不希望图像保持其原始大小,我希望图像变得小于原始大小,以防内容大于设备的高度。因此,通过将图像视图设置为较小的尺寸,所有内容都会填满设备的高度。
猜你喜欢
  • 1970-01-01
  • 2018-05-07
  • 2014-05-15
  • 2013-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-24
相关资源
最近更新 更多