带有节标题的Recycler视图,并在节标题之间重新排序单元格

时间:2017-12-15 12:43:51

标签: android-recyclerview

所以,正如问题所述。如何在android的recycler视图中添加section header,并重新排序Recycler视图的单元格。

1 个答案:

答案 0 :(得分:0)

请参阅以下代码,

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
    android:id="@+id/tv_header"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#eee"
    android:gravity="center_vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:text="Section 1"
    android:textColor="#000"
    android:textSize="18sp"
    android:textStyle="bold" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:text="item 1"
    android:gravity="center_vertical"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:textAllCaps="true"
    android:textColor="#4d4949"
    android:textSize="16sp"/>

<View
    android:layout_width="match_parent"
    android:layout_height="0.5dp"
    android:background="#000" />

我假设你现在正在做的是为每个单元格设置一个适配器布局,如果你想要有标题,你应该使你的适配器布局看起来像上面的代码, 您需要检查Adapter类中的组,无论您需要检查什么条件。默认情况下,对于每个单元格都会隐藏节标题,当满足条件时,您可以使标题对于特定单元格可见,并将所需的任何文本设置为标题。