工具栏下方的 Android RecyclerView

标签 android toolbar android-recyclerview

我有一个自定义 RecyclerView 和一个工具栏,它在向下滚动时隐藏并在向上滚动时出现。我对 RecyclerView 的位置有疑问,它在工具栏下方,我使用了该行为,但它似乎不起作用。

我的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:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

最佳答案

试试这个:

<?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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways" />

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

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

我已移除 ViewPager 并向 RecyclerView 添加滚动行为

关于工具栏下方的 Android RecyclerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31306884/

相关文章:

android - 具有多个 View 的Room DataSource.Factory RecyclerView

android - 水平 RecyclerView 高度换行内容不起作用

android - 如何在 Android Compose 中动态更新 AndroidView 内的 RecyclerView

java - 如何使用在方法内部定义的变量在java中同一类的另一个方法中使用方法外部

android - API 级别 29 java 中不推荐使用 Environment.getExternalStorageDirectory()

android - 当设置应用程序 :elevation ="0dp" then hamburgermenu not showing to toolbar

以 Nav Drawer 按钮为中心的 Android 工具栏图像

android - 如何在 View 中选择下一个和上一个编辑文本

Android Toast 不会消失

qt - (Qt) 工具栏中的两行小部件