【问题标题】:Android ignoring maxWidthAndroid忽略maxWidth
【发布时间】:2012-06-24 22:47:37
【问题描述】:

如果我尝试将 'android:maxWidth="400dp"' 添加到以下 ImageView 中,没有任何反应......还有想法吗?

<ImageView android:src="@drawable/content_background"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:contentDescription="@string/img_background" />

【问题讨论】:

  • 我猜 android:layout_width="fill_parent" 覆盖它?
  • 可能...您有什么解决方法的想法吗?

标签: android size width imageview css


【解决方案1】:

对于遇到此问题的其他任何人:我必须将其包装在 FrameLayout 中并将 maxWidth 作为其 layout_width 应用于 FrameLayout。看起来像:

<FrameLayout android:layout_width="800dp" android:layout_height="fill_parent" android:layout_centerInParent="true">
    <ImageView android:src="@drawable/content_background"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:layout_gravity="center"
                    android:adjustViewBounds="true"
                    android:contentDescription="@string/img_background" />
</FrameLayout>

其中 800dp == ImageView 的有效“最大宽度”。这也不应该干扰较小的设备。

【讨论】:

  • 但这并没有设置maxWidth,因为这种方法可以保证宽度为800dp,即使它可以更小,这也是首先使用maxWidth的重点。跨度>
猜你喜欢
  • 1970-01-01
  • 2011-07-16
  • 1970-01-01
  • 2015-03-11
  • 2015-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多