如何从顶部垂直实现可伸缩布局

时间:2021-06-26 10:51:12

标签: android xml android-layout android-linearlayout stretch

我将屏幕垂直分为两部分,在一个布局图像视图的顶部在那里,在底部布局文本视图在那里。现在,如果假设屏幕有 10 行,其中有 5 行文本,其余 5 行用于图像,那么我没有问题。但是假设现在有六行文本视图,那么我希望文本必须从顶部取一行,而图像视图布局应该只取四行以适合。我试过 minHeight 但没有得到结果,这是我的代码

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="2"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ll_image"
        android:layout_weight="1"
        android:background="#d9d9d9">
        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/imageView"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher_background"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/ll_text"
        android:layout_weight="1">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/textView"
            android:textSize="20sp"
            android:text="@string/textview"/>

    </LinearLayout>
</LinearLayout>

0 个答案:

没有答案