【问题标题】:BottomNavigationView hides some part of the screen at the bottom in my app (Android studio java)BottomNavigationView 在我的应用程序底部隐藏了屏幕的某些部分(Android Studio java)
【发布时间】:2021-04-08 20:50:11
【问题描述】:

BottomNavigationView 隐藏了屏幕后面的部分视图。

如何在页脚上方显示视图 (BottomNavigationView)

我已编辑以下内容并更新了 mainactivity.xml 文件

另外,我添加了另一个 xml 的 xml 文件,如下所示

我的一个xml

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/refresh_layout"
    android:layout_width="match_parent"
    app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
    android:layout_height="match_parent"

    android:background="@color/colorPrimary"
    tools:ignore="NotSibling,RtlHardcoded">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@null">
/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

mainactivity.xml

    <androidx.drawerlayout.widget.DrawerLayout
        android:id="@+id/root_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        android:background="@null"
        tools:ignore="NotSibling,UnknownId">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@null">

            <FrameLayout
                android:id="@+id/fragment_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@null"
                android:paddingBottom="?attr/actionBarSize"
                android:paddingTop="?attr/actionBarSize"/>

          
            <View
                android:id="@+id/divider_toolbar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/stroke"
                android:layout_marginTop="?attr/actionBarSize"
                android:background="@color/colorPrimary"/>
            <FrameLayout
                android:id="@+id/footer_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                >
                <com.google.android.material.bottomnavigation.BottomNavigationView
                    android:layout_gravity="bottom"
                    android:background="@drawable/curved_shape_footer"
                    android:id="@+id/bottom_navigation"
                    android:layout_width="match_parent"
                    app:itemBackground="?selectableItemBackgroundBorderless"
                    app:itemHorizontalTranslationEnabled="false"
                    app:menu="@menu/bottom_navigation"
                    app:labelVisibilityMode="unlabeled"
                    android:layout_alignParentBottom="true"
                    android:layout_height="wrap_content"/>
            </FrameLayout>
</...>
</...>
</...>

【问题讨论】:

    标签: java android-studio bottomnavigationview


    【解决方案1】:

    使用constraints layout 并将您的顶级根视图的约束设置为app:layout_constraintBottom_toTopOf="@id/bottomNavigationView"

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="0dp"      
        android:background="@color/colorPrimary"
        tools:ignore="NotSibling,RtlHardcoded"
         app:layout_constraintTop_toTopOf="parent" 
        app:layout_constraintBottom_toTopOf="@id/bottom_navigation">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@null">
    
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
    
    <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomNavigationView"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:menu="@menu/bottom_nav_menu" />
    
    </androidx.constraintlayout.widget.ConstraintLayout>
    

    【讨论】:

    • 我有一个 MainActivity,页脚只在主要活动中。您是否提到此 mainactivity 屏幕中需要添加的约束布局?
    • 我的意思是无论您使用哪种布局来显示底部导航上方的数据,只需添加应用程序:layout_constraintBottom_toTopOf="@id/bottomNavigationView"
    • @sejn 你能分享你的 XML 吗?
    • 在我的 mainactivity.xml 中,我已经像上面一样添加了,在每个 xml 中我也像上面一样添加了。
    • 谢谢@sejn,你把底部导航视图放在哪里了?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-08
    • 2019-04-28
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    • 2012-12-07
    • 1970-01-01
    相关资源
    最近更新 更多