【发布时间】:2014-06-18 23:37:00
【问题描述】:
我有一个包含 5 个图像视图的水平线性布局。每个图像视图的宽度不同,但高度相同。 在横向看起来很好(下图 1),但是当我将线性布局调整为纵向时,最后一个图像无法适应,而倒数第二个被缩放以适应(下图 2)。 我想要的是所有图像都可以缩放以适应线性布局(下图 3)。
这可能吗?
也许有一种方法可以创建固定纵横比的LinearLayout?这样,图像将调整到 LinearLayout 的高度,LinearLayout 的高度将调整以保持与 LinearLayout 的宽度的纵横比,LinearLayout 的宽度将调整以适应屏幕。
布局将是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/image_01">
</ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/image_02">
</ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/image_03">
</ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/image_04">
</ImageView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/image_05">
</ImageView>
</LinearLayout>
</RelativeLayout>
对每个图像使用 android:layout_weight="1" 不起作用。我明白了:
【问题讨论】:
-
你能发布你的布局文件吗?
标签: android imageview width android-linearlayout