Android用户界面:用最大高度限制填充剩余屏幕

Android用户界面:用最大高度限制填充剩余屏幕,android,android-layout,Android,Android Layout,我想知道如何在androidxml中实现以下设计。内容将具有最高优先级的高度环绕内容,如果有足够的内容,它甚至可以填充整个屏幕。上面的图像应该填满剩余的高度-但是它也有一个限制的最大高度160dp。似乎如果我使用布局权重或匹配父级,“最大高度”参数不再起作用。在xml中是否有这样做的方法?或者我必须以编程方式在Java文件中执行此操作?谢谢 试试这样的方法: 我使用两个文本视图只是为了测试 <?xml version="1.0" encoding="utf-8"?> <andr

我想知道如何在androidxml中实现以下设计。内容将具有最高优先级的高度环绕内容,如果有足够的内容,它甚至可以填充整个屏幕。上面的图像应该填满剩余的高度-但是它也有一个限制的最大高度160dp。似乎如果我使用布局权重或匹配父级,“最大高度”参数不再起作用。在xml中是否有这样做的方法?或者我必须以编程方式在Java文件中执行此操作?谢谢


试试这样的方法:

我使用两个文本视图只是为了测试

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#42A5F5">

    <TextView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#EC407A"
        android:maxHeight="160dp"
        android:text="Image"
        android:textSize="48sp"
        app:layout_constrainedHeight="true"
        app:layout_constraintBottom_toTopOf="@+id/textView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#FFEE58"
        android:text="Content"
        android:textSize="48sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

</androidx.constraintlayout.widget.ConstraintLayout>

试着这样做:

我使用两个文本视图只是为了测试

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#42A5F5">

    <TextView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#EC407A"
        android:maxHeight="160dp"
        android:text="Image"
        android:textSize="48sp"
        app:layout_constrainedHeight="true"
        app:layout_constraintBottom_toTopOf="@+id/textView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#FFEE58"
        android:text="Content"
        android:textSize="48sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

</androidx.constraintlayout.widget.ConstraintLayout>