ScrollView 及其内容使用 'wrap_content'。如何分配约束优先级?

ScrollView and its content use 'wrap_content'. How to assign constraint priority?

我需要水平 ScrollView,固定高度 100dp 和 ImageViews 的动态内容。

目前我的 ScrollView 有一个水平 LinearLayoutImageViews。 ImageView 的宽度启用了 wrap_content,而所有高度都处于固定高度。 ScrollView 本身的高度在 wrap_content.

如果 ScrollViews 内容大于视图在不滚动的情况下可以显示的内容,ImageViews 图像将按比例缩小。 ImageViews layout_hight 根据其边界工作,但图像本身不是。

scaleType 更改为其他内容无济于事。为 LinearLayout 设置固定宽度是可行的,但由于内容应该是动态的,所以这不是一个选项。这似乎是一个默认用例。这在 xml 中是不可能的吗?

带有手动给定的确切 ScrollView 宽度的示例:

视图符合我的需要,但不允许动态内容。

宽度为 wrap_content 的示例:

ImageView

下面的 ScrollView 代码:

<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>

好的,这比我想象的更容易解决:

ScrollViews 总是垂直的。 ScrollView 中没有 orientation 属性。要获得水平滚动视图,请改用 HorizontalScrollView 并放弃方向。

所以这个

<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

应该改为:

<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">