我正在尝试构建一个遵循Google指南的列表视图。Android材质ListView分隔线
这里是我的要求:
- 允许组头
- 允许组之间全宽分隔
- 允许项之间局部分隔
这里是一个图像示出了报头和项目之间的分隔线。 不幸的是,无法查看组之间的全宽分隔线,但这就像普通的分隔线一样。
我可以建立接收的Item
子类,像HeaderItem
和ContactItem
自定义适配器。
的header.xml
将仅仅是
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:padding="16dp"
android:text="Today"
android:textColor="#8A000000"
android:textSize="14sp" />
对于contact.xml
:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/friend_profile_picture"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="16dp"
android:scaleType="fitStart"
android:src="@drawable/ic_home" />
<TextView
android:id="@+id/friend_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@+id/friend_profile_picture"
android:paddingTop="16dp"
android:text="random_text"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
<TextView
android:id="@+id/friend_state"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/friend_name"
android:layout_toRightOf="@+id/friend_profile_picture"
android:paddingBottom="16dp"
android:text="random_text"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="14sp" />
</RelativeLayout>
现在,我的问题是,该项目分频。全宽分隔符将是一个正常的列表视图分隔符。我只是不知道如何做一个部分dividir,并使其与正常的分频器一起工作。任何提示?
如果更容易/更好,也可以用RecyclerView
和ItemDecorator
来完成。
添加视图/ LinearLayout/RelativeLayou t在“friend_state”Tetview之下,黑色背景和左边填充/边距72dp。 – Sabari
好的,但是这样做会显示行,然后显示列表视图的分隔符。 现在只是缺少如何使listview分隔符仅在部分之间可见。 – HelderMPinhal
请参考此链接,这可能会帮助你[链接](http://codingdiscovery.blogspot.in/2015/02/android-listviews-with-headers.html) – Sabari