提问者:小点点

BottomNavigationView和AppBar覆盖了recyclerview的片段


我对放置片段并使其滚动而不被bottomNavigationView和appbar重叠有一个问题。 所以我的内容被BottomNavigationView和appBar覆盖了。我如何使我的内容在我滚动页面时可见,或者使appBar和BottomNavigationView在向下滚动页面时不可见?

我的activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawerLayout"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity">

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

    <androidx.appcompat.widget.Toolbar
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:id="@+id/mainToolbar"
        style="@style/mainToolbar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:elevation="0dp"
        />

    <View
        android:layout_width="match_parent"
        android:layout_height="8dp"
        app:layout_constraintBottom_toTopOf="@id/bottomNavigationView"
        android:background="@drawable/shadow"/>


    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:menu="@menu/bottom_menu"/>

    <fragment
        android:layout_marginTop="130dp"
        android:id="@+id/dataContainer"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="409dp"
        android:layout_height="673dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/mainToolbar"
        app:navGraph="@navigation/my_nav" />

</androidx.constraintlayout.widget.ConstraintLayout>

<com.google.android.material.navigation.NavigationView
    android:id="@+id/navView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:headerLayout="@layout/nav_header"
    app:menu="@menu/nav_drawer_menu"
    android:layout_gravity="start"
    android:fitsSystemWindows="true" />

</androidx.drawerlayout.widget.DrawerLayout>

fragment_home.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
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=".fragments.general.HomeFragment">
<View
    android:layout_width="match_parent"
    android:layout_height="8dp"
    app:layout_constraintTop_toTopOf="parent"
    android:background="@drawable/shadow_top"/>

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/recycler_view_item"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

和recycler_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView 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="147dp"
xmlns:tools="http://schemas.android.com/tools"
android:layout_marginBottom="15dp"
android:layout_marginEnd="30dp"
app:cardCornerRadius="12dp"
app:cardElevation="5dp"
android:layout_marginTop="15dp"
android:layout_marginStart="30dp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="false">


<RelativeLayout
    android:id="@+id/relative"
    android:layout_width="147dp"
    android:layout_height="147dp"
    >

 <ImageView
     android:id="@+id/nailImageView"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:background="#000"
     android:src="@drawable/image_3__2_"
     android:tint="#40000000"
     tools:ignore="ContentDescription" />

<ImageView
    android:id="@+id/imageNailService"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="40dp"
    android:layout_centerHorizontal="true"
    android:src="@drawable/ic_nail_service"
    android:layout_gravity="center"
    />

<TextView
    android:id="@+id/textNailService"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Nail услуги"
    android:textColor="#fff"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="30dp"
    android:layout_alignParentBottom="true"
    android:textSize="15sp"
    android:textStyle="bold"
    />

</RelativeLayout>
</androidx.cardview.widget.CardView>

有什么解决办法吗?


共1个答案

匿名用户

设定包含nav主机片段0dp的片段标记的高度