如何在 Android Activity 中使可滚动布局后面跟着另一个布局(第二部分)

问题描述 投票:0回答:1

这是如何在 Android Activity 中使可滚动布局后面跟着另一个布局

的延续

我使用了Finn Marquardt提出的解决方案。

与上一篇文章的期望相比,我现在希望 ScrollView 位于一个块中,该块还包含标题和要在该块周围显示的边框,如下所示:

我设法通过添加一个额外的 FrameLayout 只是为了显示边框来做到这一点。

这是代码:

<?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:id="@+id/prop1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="8dp"
    >

    <FrameLayout android:id="@+id/extra_layout"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@drawable/border"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@id/title_block"
        app:layout_constraintBottom_toBottomOf="@id/scrollView" />

    <LinearLayout android:minHeight="100dp"
            android:id="@+id/title_block"
            android:paddingVertical="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" >
        <TextView android:minHeight="100dp"
        android:id="@+id/title"
        android:layout_marginHorizontal="16dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#cccccc"
        android:text="TITLE"
        />
    </LinearLayout>

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="16dp"
        android:paddingBottom="8dp"
        app:layout_constraintHeight_max="wrap"
        app:layout_constraintVertical_bias="0"
        app:layout_constraintTop_toBottomOf="@id/title_block"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/button">

        <TableLayout
            android:id="@+id/table"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <TableRow android:background="#ff9999">
                <TextView android:minHeight="100dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="first row"/>
            </TableRow>
            <TableRow android:background="#99ff99">
                <TextView android:minHeight="100dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="second row"/>
            </TableRow>
            <TableRow android:background="#bbbbff">
                <TextView android:minHeight="100dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="third row"/>
            </TableRow>
        </TableLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_marginTop="8dp"
        android:background="@drawable/border"
        android:orientation="vertical"
        app:layout_constraintVertical_bias="0"
        app:layout_constraintTop_toBottomOf="@id/scrollView"
        app:layout_constraintBottom_toTopOf="@id/button"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="validate"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

但我不喜欢仅仅为边框添加人工布局的想法。 我希望有一个布局(带边框),包括标题和 ScrollView。

我怎样才能做到这一点?

android android-layout layout
1个回答
0
投票

我建议您使用两个回收器视图,默认情况下是可滚动的。

© www.soinside.com 2019 - 2024. All rights reserved.