底部导航和片段重叠

时间:2019-05-27 03:15:01

标签: android android-fragments scrollview bottomnavigationview

如您在这张图片中所见

底部导航和文本字段重叠。

我的应用出现这种怪异行为的原因是什么?

这是xml:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context=".fragment.ApplicationFragment">
    <androidx.core.widget.NestedScrollView
        android:id="@+id/scroll_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:paddingLeft="5dp"
        android:fillViewport="true">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:baselineAligned="false">
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/text_amount_applied"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        app:errorEnabled="true">
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/amount_edit_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:maxLines="1"
                            android:inputType="numberDecimal"
                            android:hint="Amount Applied" />
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:hint="Mode of payment">
                        <AutoCompleteTextView
                            android:id="@+id/filled_exposed_dropdown"
                            android:layout_width="match_parent"
                            android:maxLines="1"
                            android:editable="false"
                            android:layout_height="wrap_content"/>
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/text_term"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        app:errorEnabled="true">
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/term_edit_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:maxLines="1"
                            android:inputType="number"
                            android:hint="Term" />
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
            </LinearLayout>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="INDIVIDUAL INFORMATION"
                android:textSize="20dp"
                android:layout_marginBottom="10dp"/>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:baselineAligned="false">
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/text_last_name"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        app:errorEnabled="true">
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/lastname_edit_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:maxLines="1"
                            android:hint="Lastname" />
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/text_first_name"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        app:errorEnabled="true">
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/firstname_edit_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:maxLines="1"
                            android:hint="Firstname" />
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/text_middle_name"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        app:errorEnabled="true">
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/middlename_edit_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:maxLines="1"
                            android:hint="Middlename" />
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:baselineAligned="false">
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/text_birthdate"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        app:errorEnabled="true">
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/birthdate_edit_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:maxLines="1"
                            android:editable="false"
                            android:inputType="date"
                            android:hint="Birthdate" />
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        android:id="@+id/text_age"
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        app:errorEnabled="true">
                        <com.google.android.material.textfield.TextInputEditText
                            android:id="@+id/age_edit_text"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:maxLines="1"
                            android:inputType="number"
                            android:hint="Age" />
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
                <RelativeLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1">
                    <com.google.android.material.textfield.TextInputLayout
                        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="5dp"
                        android:hint="Sex">
                        <AutoCompleteTextView
                            android:id="@+id/sex_exposed_dropdown"
                            android:layout_width="match_parent"
                            android:maxLines="1"
                            android:editable="false"
                            android:layout_height="wrap_content"/>
                    </com.google.android.material.textfield.TextInputLayout>
                </RelativeLayout>
            </LinearLayout>
    </androidx.core.widget.NestedScrollView>
</FrameLayout>

这是activity_main.xml

<com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout
    android:id="@+id/frame_container"
    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">

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottom_navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:itemBackground="@color/colorPrimary"
        android:foreground="?attr/selectableItemBackground"
        app:itemIconTint="@android:color/white"
        app:itemTextColor="@android:color/white"
        app:menu="@menu/bottom_nav_menu" />

</com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout>

顺便说一句,我只是复制,复制和粘贴了生日,年龄和性别的10倍或更次,以测试片段是否在滚动。最终,在我运行该应用程序之后,如您在图片中看到的,底部导航和文本字段现在重叠了。

1 个答案:

答案 0 :(得分:2)

假设您的participant.competitions # returns relationship object 高度为60dp,可以通过将此属性添加到您的BottomNavigationView

来避免这种情况
NestedScrollView
相关问题