use*_*408 36 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>
Hải*_*yễn 51
<?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添加了滚动行为
war*_*ero 42
如果添加滚动行为无法解决您的问题
app:layout_behavior="@string/appbar_scrolling_view_behavior"
然后尝试这个
我必须给recyclelerview提供填充,这相当于toolbar/actionbar(app bar)的高度.
  android:paddingTop="?attr/actionBarSize"  
将以上行添加到recyclerview xml文件中
Rav*_*ian 14
当我从其他布局中包含RecyclerView时,出现了同样的问题.我在recyclerview上添加了以下这一行,问题不再存在.
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
错过上面的这行就会出现这个问题.
您需要将此属性添加到您的 RecyclerView:
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
IE:
<android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
| 归档时间: | 
 | 
| 查看次数: | 29663 次 | 
| 最近记录: |