底部导航覆盖的最后一项

时间:2019-04-11 09:52:41

标签: android android-recyclerview bottomnavigationview

所以,我有这个问题。我的底部导航覆盖了recyclerview的最后一项。底部导航处于活动状态。 recyclerview在片段中。我没有找到答案。

这是我的片段布局,其中包含recyclerview

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".PromoFragment">

    <!-- TODO: Update blank fragment layout -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/promo_recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginBottom="110dp">

    </android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>

这是我在recyclerview中使用的物品布局

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="5px">

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:layout_marginEnd="8dp"
            android:id="@+id/card_pertama"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

               <include layout="@layout/card_promo_layout"/>

        </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>

这是我的代码结果的图片

enter image description here

4 个答案:

答案 0 :(得分:1)

我有同样的问题。我确实使用RV的项装饰并抵消了底部导航栏高度的最新项(通常与动作栏的高度相同)来修复它。 EG

 mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
           @Override
           public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
               int position = parent.getChildAdapterPosition(view);
               if (position == parent.getAdapter().getItemCount() - 1) {
                      outRect.bottom = bottomMargin;
                }
             }
   });

答案 1 :(得分:1)

android:paddingBottom="56dp"添加到包含Fragment的{​​{1}}或RecyclerView的最接近的父布局中。例如:

RecyclerView

P.S。 56dp-根据材料设计,<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingBottom="56dp" tools:context=".PromoFragment"> <!-- TODO: Update blank fragment layout --> <android.support.v7.widget.RecyclerView android:id="@+id/promo_recyclerview" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> </android.support.v7.widget.RecyclerView> </android.support.constraint.ConstraintLayout> 的高度。因此BottomNavigationView的值必须与paddingBottom的高度相同

答案 2 :(得分:1)

将底部导航更改为此

<FrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/navigationView" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigationView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/windowBackground"
    android:layout_alignParentBottom="true"
    app:menu="@menu/your_menu" />

并将布局更改为RelativeLayout

答案 3 :(得分:1)

您可以使用此android:clipToPadding =“ false”并在RecyclerView中添加android:paddingBottom =“导航栏的高度”属性

    <android.support.v7.widget.RecyclerView
            android:id="@+id/promo_recyclerview"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:paddingBottom="height of the navigation bar"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginBottom="110dp"/>
相关问题