1

如果我尝试将 '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" />
4

1 回答 1

-1

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

<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 的有效“最大宽度”。这也不应该干扰较小的设备。

于 2012-06-22T16:14:21.183 回答