android - 如何让TextView跟着RecyclerView滚动?

查看:145
本文介绍了android - 如何让TextView跟着RecyclerView滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

想要实现下面这张图里面的「Google+上的最新热点信息」的样子,也就是RecyclerView中间分隔的部分插入了文字,而且可以跟RecyclerView一起滚动。

我试过在RecyclerView前面加TextView(下图的2015年12月10日),但是不行,TextView并不能随着卡片滚动,而且我这里只是在RecyclerView的开头加了TextView:

请问应该怎么实现第一张图里面的TextView随着卡片滚动的效果?那个TextView也是一个RecyclerView吗?谢谢

附第二张图的XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_refresh_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#F0F0F0"
    android:orientation="vertical">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/date_show"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="10.0dip"
            android:text="2015年12月10日"
            android:textSize="15.0sp" />
        <android.support.v7.widget.RecyclerView
            android:id="@+id/cards_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipToPadding="false"
            android:scrollbarStyle="outsideOverlay"
            android:scrollbars="vertical" />
    </LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>



解决方案

有一种实现方法:recyclerView的Adapter有一个getItemViewType()方法 可以根据需求跟换item布局
实现方法可以参考:https://segmentfault.com/a/1190000004854818

这篇关于android - 如何让TextView跟着RecyclerView滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆