想要实现下面这张图里面的「Google+上的最新热点信息」的样子,也就是RecyclerView中间分隔的部分插入了文字,而且可以跟RecyclerView一起滚动。
我试过在RecyclerView前面加TextView(下图的2015年12月10日),但是不行,TextView并不能随着卡片滚动,而且我这里只是在RecyclerView的开头加了TextView:
请问应该怎么实现第一张图里面的TextView随着卡片滚动的效果?那个TextView也是一个RecyclerView吗?谢谢
附第二张图的XML:
类似ListView,有两种viewType.
感觉最简单的方法就是利用CoordinatorLayout和AppBarLayout,将TextView放进AppBarLayout中,然后将AppBarLayout和RecyclerView都放进CoordinatorLayout中。但是这样做有个缺陷就是AppBarLayout会自带主题,这会影响我们TextView的背景颜色等,所以需要我们手动设置一些属性来屏蔽来自AppBarLayout自带主题的影响。
我的示例代码(仅仅只屏蔽了AppBarLayout背景颜色的影响)
<android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:background="@color/white" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/text_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Hello" app:layout_scrollFlags="scroll" /> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" > </android.support.v7.widget.RecyclerView> </android.support.design.widget.CoordinatorLayout>
有一种实现方法:recyclerView的Adapter有一个getItemViewType()方法 可以根据需求跟换item布局
实现方法可以参考:https://segmentfault.com/a/1190000004854818