android垂直滚动视图布局,使ImageView具有固定的屏幕高度百分比

android垂直滚动视图布局,使ImageView具有固定的屏幕高度百分比,android,android-layout,android-layout-weight,Android,Android Layout,Android Layout Weight,嗨,我是android开发的新手。 我想设计一个包含ImageView和TextView的垂直滚动视图。ImageView占据屏幕顶部50%的高度,底部是动态内容的TextView,它可能占据屏幕高度的50%以下或以上。因此,只有文本内容占据屏幕50%以上时,ScrollView才可滚动(请参见下面的示例) 有没有办法实现这种布局 <ScrollView android:layout_width="match_parent" android:layout_height="

嗨,我是android开发的新手。 我想设计一个包含ImageView和TextView的垂直滚动视图。ImageView占据屏幕顶部50%的高度,底部是动态内容的TextView,它可能占据屏幕高度的50%以下或以上。因此,只有文本内容占据屏幕50%以上时,ScrollView才可滚动(请参见下面的示例)

有没有办法实现这种布局

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/scroll_image"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="centerCrop" />

        <TextView
            android:id="@+id/scroll_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</ScrollView>
希望这有帮助。

尝试下面的代码

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="100"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/scroll_image"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:scaleType="centerCrop"
                    android:layout_weight="50" />

                <TextView
                    android:id="@+id/scroll_text"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="50" />
            </LinearLayout>
        </ScrollView>

尝试线性布局权重和。
<ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="100"
                android:orientation="vertical">

                <ImageView
                    android:id="@+id/scroll_image"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:scaleType="centerCrop"
                    android:layout_weight="50" />

                <TextView
                    android:id="@+id/scroll_text"
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="50" />
            </LinearLayout>
        </ScrollView>