【问题标题】:Bottom Navigation and Fragment is overlapping底部导航和片段重叠
【发布时间】:2019-05-27 03:15:01
【问题描述】:

正如你在这张照片中看到的

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

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

这里是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 次或更多次的 Birthdate、Age 和 sex,以测试片段是否正在滚动。最终在我运行应用程序后,如图所示,底部导航和文本字段现在重叠。

【问题讨论】:

  • 如果您向我展示您的 main_activity XML 文件,您在其中显示bottomNavigationView,可以吗?因为问题就在那里。
  • @DPrince 添加了 xml。请检查一下
  • 为什么使用 CircularRevealCoordinatorLayout 以及片段加载布局在哪里。
  • 不好用吗?
  • 如果你想出于某种目的使用它就可以使用,否则不好使用。

标签: android android-fragments scrollview bottomnavigationview


【解决方案1】:

假设您的 BottomNavigationView 高度为 60dp ,您可以通过将此属性添加到您的 NestedScrollView 来避免这种行为

  android:layout_marginBottom="60dp"

【讨论】:

    猜你喜欢
    • 2020-03-23
    • 1970-01-01
    • 2018-11-04
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多