如何停止底部导航栏与RecyclerView重叠?

4

https://istack.dev59.com/Ymbrj.gif

如何停止Android底部导航栏重叠RecyclerView? 我需要解决这个问题,但我不知道该怎么办。我尝试了很多方法,最终无法解决。我需要你的帮助。 我阅读了当前的主题,我认为我的问题更加全面。RecyclerView在屏幕上打印CardView。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="match_parent"
    android:fitsSystemWindows="true"


    xmlns:design="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.hasan.simpleblog.MainActivity">


    <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="#ffffff"

            >

            <android.support.design.widget.BottomNavigationView
                android:id="@+id/NavBot"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"

                android:layout_gravity="bottom"
                android:background="#ffff"
                design:menu="@menu/menu_nav"

                >

                <View
                    android:id="@+id/view"
                    android:layout_width="match_parent"
                    android:layout_height="4dp"
                    android:background="@color/colorPrimary" />
            </android.support.design.widget.BottomNavigationView>

            <android.support.v4.view.ViewPager
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/bottom_navigation"
                android:layout_alignParentTop="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" >

            </android.support.v4.view.ViewPager>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/blog_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="?attr/actionBarSize"
            tools:layout_editor_absoluteX="8dp"
            tools:layout_editor_absoluteY="8dp">

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

    </FrameLayout>
    </android.support.design.widget.CoordinatorLayout>

你提供的图片不是来自这个布局,对吗? - Vinayak B
在RecyclerView上移除底部边距。 - Sarthak Gandhi
是的,我的布局不同。 - user8312867
添加你的截图 - Stanislav Batura
2个回答

4

使用ConstraintLayout布局。 将上方视图的底部边缘与下方视图的顶部边缘对齐。

示例

xml

    <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:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ListView
    android:id="@+id/list_item"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:divider="@color/black"
    android:dividerHeight="2dp"
    app:layout_constraintBottom_toTopOf="@+id/navigation"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="1.0"
    app:layout_constraintHorizontal_bias="1.0"></ListView>

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="?android:attr/windowBackground"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:menu="@menu/navigation" />
      </android.support.constraint.ConstraintLayout>

设计

图片描述在这里输入


0

如果您使用CoordinatorLayout(如上所示),您可以自定义视图行为以执行完全相同的操作。

以下是一些很棒的帖子:

BignerdRanch教程

Ian Lake介绍


我无法处理它。 - user8312867
像这个问题。您可以尝试其中一个答案 https://dev59.com/UF0a5IYBdhLWcg3wCE7P - Son Tieu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接