Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

android - How to fix a bottom navigation bar when Constraint layout is within ScrollView?

I have constraint layout within Scrollview in my xml file, and I want a fixed navigation bar at the bottom of the mobile screen which cannot be scrolled when I scroll the page. How do I fix the bottom navigation bar at the bottom of the mobile screen when my constraint layout is within the Scrollview (because I want the entire page content to scroll when I scroll)? Attached is the xml layout file. This is the image of the bottom navigation bar.

XML layout file with Constraint layout within ScrollView -

<?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>

question from:https://stackoverflow.com/questions/65900631/how-to-fix-a-bottom-navigation-bar-when-constraint-layout-is-within-scrollview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can do it this way.

<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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...