使用AppBarLayout时,RecyclerView的最后一项被隐藏

时间:2018-03-29 10:54:28

标签: android android-recyclerview

在第二张图片中,项目滚动到屏幕底部,项目的一部分隐藏在BottomNavigationView后面。

activity_main.xml中:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    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"
    android:orientation="vertical">
    <FrameLayout
        android:id="@+id/main_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/navigation">
    </FrameLayout>
    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        android:layout_alignParentBottom="true"
        app:menu="@menu/navigation"
        />
</RelativeLayout>

activity_dynamic_recycler.xml:

<?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"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="110dp"
            android:id="@+id/appbar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">
            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/collapsing_toolbar"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:contentScrim="?attr/colorPrimary"
                app:title="@string/title_places"
                app:expandedTitleMarginStart="72dp"
                app:expandedTitleTextAppearance="@style/ExpandedAppbar"
                app:collapsedTitleTextAppearance="@style/CollapsedAppbar">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/header_text_layout"
                    android:background="?attr/colorPrimary"
                    android:layout_gravity="bottom"
                    android:gravity="center_vertical"
                    android:paddingLeft="72dp"
                    android:paddingRight="10dp"
                    android:paddingTop="5dp"
                    android:paddingBottom="5dp"
                    android:orientation="vertical">
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/subtitle"
                        android:textColor="@android:color/darker_gray"
                        android:textSize="16sp"
                        android:text="@string/my_location"/>
                </LinearLayout>
                <android.support.v7.widget.Toolbar
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:id="@+id/fragment_places_toolbar"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
        <android.support.v7.widget.RecyclerView
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            android:id="@+id/recyclerView">
        </android.support.v7.widget.RecyclerView>
    </android.support.design.widget.CoordinatorLayout>

以下是图片:

enter image description here

enter image description here

尝试向recyclerview添加保证金/填充 - 没有帮助。没有找到类似问题的AppbarLayout和NavigationView的情况。任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:1)

你可以尝试通过分离事物来做到这一点。

activity_main.xml中

<android.support.design.widget.CoordinatorLayout 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="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:theme="@style/ThemeOverlay.AppCompat.Dark">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll|enterAlways"
            app:contentInsetStart="@dimen/fab_margin"/>

    </android.support.design.widget.AppBarLayout>

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="?android:attr/windowBackground"
        app:menu="@menu/navigation" />
</android.support.design.widget.CoordinatorLayout>

activity_dynamic_recycler.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent"
    android:layout_marginBottom="?attr/actionBarSize"
    xmlns:tool="http://schemas.android.com/tools"
    android:orientation="vertical"
    tool:context=".MainActivity">

<android.support.v7.widget.RecyclerView
    android:id="@+id/theory_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbarStyle="outsideOverlay"
    android:divider="@color/list_divider"
    android:dividerHeight="1dp"
    android:listSelector="@drawable/list_row_selector"
    android:paddingBottom="48dp"
    android:clipToPadding="false" />

</FrameLayout>

答案 1 :(得分:0)

设置RecyclerView layout_marginBottom =“110dp”,因为您的AppBarLayout layout_height =“110dp”。

<android.support.v7.widget.RecyclerView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        android:id="@+id/recyclerView"
        android:layout_marginBottom="110dp">
    </android.support.v7.widget.RecyclerView>

答案 2 :(得分:0)

根据Google Design Spec底部导航栏应该隐藏在滚动

实施:https://www.stackoverflow.com/a/44778453