【问题标题】:Last item covered by bottom navigation底部导航覆盖的最后一项
【发布时间】:2019-04-11 09:52:40
【问题描述】:

所以,我有这个问题。我的最后一项 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>

这是我的代码结果的图像

【问题讨论】:

    标签: android android-recyclerview bottomnavigationview


    【解决方案1】:

    android:paddingBottom="56dp" 添加到包含RecyclerViewFragmentRecyclerView 最接近的父布局。例如:

    <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>
    

    附: 56dp - 是 BottomNavigationView 根据 Material Design 的高度。所以paddingBottom的值必须和BottomNavigationView的高度一致

    【讨论】:

    • 其实可以的。我以前用过marginBottom,但没用。衬垫是完美的。谢谢
    【解决方案2】:

    把你的底部导航改成这个

    <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

    【讨论】:

    • 使用framelayout和relativelayout有什么区别?我认为这是相同的想法
    • 参考this了解它们之间的区别
    【解决方案3】:

    我遇到了同样的问题。我确实使用 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;
                    }
                 }
       });
    

    【讨论】:

      【解决方案4】:

      您可以使用这个 android:clipToPadding="false" 并在 RecyclerView 中添加 android:paddingBottom="height of the navigation bar" 属性

          <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"/>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多