2016-08-18 71 views
0

我已经回收view.At位置0,我做了标题,并从位置1对其余项目将come.This是我的布局如何在RecyclerView android位置停止特定视图的滚动?

<android.support.design.widget.CoordinatorLayout 
    android:id="@+id/main_content" 
    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.v4.widget.SwipeRefreshLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/swipe_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="2dp"> 

     <android.support.v7.widget.RecyclerView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/recyler_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="2dp" 
      android:background="@color/listview" 
      /> 

    </android.support.v4.widget.SwipeRefreshLayout> 


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

我想,当我滚动我的看法回收,并在半的头部向上滚动,剩余的头部在顶部粘住,其他项目的回收器视图滚动。并且在某点之后,头部的粘性部分也向上移动。如何实现它。

+0

我会诚实地处理,如果它要需要是_that_动态再循环器视图的外报头视图;标题在概念上并不困难,但让这样一个人滑进和滑出这样的一半似乎可能是一个真正的挑战。 – zgc7009

+0

如何处理回收站视图以外的页眉视图,以便页眉只滚动一半然后粘贴。 –

+0

你可以尝试做一些事情,例如只是让RecyclerView正常滚动,但是检测第一个项目是否到达中间位置时,一旦它出现,就会有一个叠加视图,该视图映射出离屏幕一半的第一个项目。这会让人错觉,第一个项目已经停在顶部作为标题,实际上它正在与适配器的其余部分一起滚动。当第一个项目回到视图并处理标题视图的可见性时,请检查向下滚动。就在我的头顶,并不是说这是最好的解决方案。 – zgc7009

回答

0

要制作一个粘性标题,您需要为RecyclerView提供ItemDecorator 如果您想要执行类似this的操作。 图书馆目前没有维护。你需要自己做一些改变。

ItemDecorator如何工作的: - ItemDecorator赋予你力量画点什么了RecyclerView。在你的情况下,你想在一段时间内放置一个粘性标题,在下一个标题项目之后,你想用较早的标题替换新的标题。

因此,使用ItemDecorator,您可以在RecyclerView顶部位置上绘制相同的标题视图,它看起来像用户,因为标题项目在顶部固定,当下一个标题项目到来时,它将用新的标题项目替换。

希望它会帮助你。

相关问题