当约束布局在 ScrollView 中时,如何修复底部导航栏?

问题描述

我在我的 xml 文件中的 Scrollview 中有约束布局,我想要在移动屏幕底部一个固定的导航栏,当我滚动页面时无法滚动。当我的约束布局在 Scrollview 中时,如何修复移动屏幕底部底部导航栏(因为我希望滚动时整个页面内容都滚动)?附件是xml布局文件 This is the image of the bottom navigation bar.

在 ScrollView 中带有约束布局的 XML 布局文件 -

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    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:orientation="vertical">

<ScrollView
    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="@drawable/background"
    android:id="@+id/exception_handling_layout"
    android:fillViewport="true">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <ImageView
            android:id="@+id/ebackarrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"

            android:src="@drawable/backarrow"

            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.039"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.124" />

        <TextView
            android:id="@+id/ebackToDashboard"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Exception Handling"
            android:textColor="@color/white"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.11"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.117" />

        <TextView
            android:id="@+id/textView100"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="Please provide a comment if you have any"
            android:textColor="@color/white"

            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.11"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.19" />

        <androidx.cardview.widget.CardView
            android:id="@+id/cardViewException"
            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"
            android:layout_marginBottom="20dp"

            app:cardCornerRadius="6dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView100"
            app:layout_constraintVertical_bias="0.03">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/teal"
            android:paddingBottom="20dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cardView">

        <TextView
            android:id="@+id/subjectText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="10dp"
            android:padding="5dp"
            android:text="Subject"
            android:textSize="16sp"

            android:textColor="@color/white"
            android:textStyle="bold" />

            <androidx.cardview.widget.CardView
                android:layout_width="345dp"
                android:layout_height="wrap_content"
                android:layout_marginTop="50dp"
                android:layout_marginLeft="16dp"
                android:id="@+id/exceptioncardview"
                android:background="@color/teal"
                app:cardCornerRadius="6dp"

                app:layout_constraintTop_toBottomOf="@+id/subjectText">


                    <Spinner
                        android:id="@+id/spinnerExceptionHandling"
                        android:layout_width="match_parent"
                        android:layout_height="50dp"

                        android:gravity="center"/>

            </androidx.cardview.widget.CardView>

            <TextView
                android:id="@+id/commentstext"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="20dp"
                android:layout_marginTop="130dp"
                android:padding="5dp"
                android:text="Comments"


                android:textColor="@color/white"
                android:textStyle="bold"
                android:textSize="16sp"
                app:layout_constraintTop_toBottomOf="@+id/exceptioncardview"/>


            <EditText
                android:id="@+id/commentsExceptionHandling"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_marginTop="170dp"
                android:layout_marginLeft="20dp"
                android:layout_marginRight="20dp"
                android:layout_marginBottom="30dp"
                android:background="@drawable/commentedittext"
                android:hint="Type here..."
                android:gravity="top"
                android:paddingLeft="20dp"
                android:paddingTop="15dp"/>





        </RelativeLayout>

        </androidx.cardview.widget.CardView>

        <Button
            android:id="@+id/submitexceptionhandlingBtn"
            android:layout_width="375dp"
            android:layout_height="wrap_content"
            android:textAllCaps="false"
            android:padding="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/flightclosurebutton"
            android:text="Submit"
            android:textStyle="bold"
            android:textColor="@color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/cardViewException"


            app:layout_constraintVertical_bias="0.0" />


    </androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/bottom_navigation" />
    
    
</LinearLayout>

解决方法

你可以这样做。

<LinearLayout
    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:orientation="vertical">
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@drawable/background"
        android:id="@+id/exception_handling_layout"
        android:fillViewport="true">

        <!--    Your content goes here    -->

    </ScrollView>
        <!--  Bottom nav goes here  -->
    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:menu="@menu/bottom_navigation" />
</LinearLayout>

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...