我需要一个ScrollView
具有固定高度100dp
和动态内容的 ImageViews 水平。
目前我的 ScrollView 有一个水平LinearLayout
的ImageView
s。ImageViews 已经wrap_content
启用了它们的宽度,而所有它们的高度都是固定的。ScrollView 本身的高度为wrap_content
.
如果 ScrollViews 的内容大于视图可以在不滚动的情况下显示的内容,则 ImageViews 图像将按比例缩小。ImageViewslayout_hight
根据其边界工作,但图像本身不是。
换成scaleType
别的没用。为 LinearLayout 设置固定宽度是可行的,但由于内容应该是动态的,所以这不是一个选项。这似乎是一个默认用例。这不可能xml
吗?
手动给定精确 ScrollView-width 的示例:
该视图看起来像我需要的那样,但不允许动态内容。
宽度为 on 的示例wrap_content
:
图像视图
滚动视图代码如下:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#CCCCFF">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#AAAAFF"
android:orientation="horizontal">
<ImageView
android:id="@+id/so1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:background="#FF0000"
android:scaleType="fitCenter"
android:src="@drawable/so" />
<Space
android:layout_width="10dp"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/so2"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:background="#FF0000"
android:scaleType="fitCenter"
android:src="@drawable/so" />
<Space
android:layout_width="10dp"
android:layout_height="match_parent" />
<ImageView
android:id="@+id/so3"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:background="#FF0000"
android:scaleType="fitCenter"
android:src="@drawable/so" />
</LinearLayout>
</ScrollView>