【问题标题】:How to create an item divider like those in WhatsApp?如何创建类似于 WhatsApp 中的项目分隔符?
【发布时间】:2018-06-27 06:36:40
【问题描述】:

如何在 WhatsApp 中的 recyclerview 元素之间创建项目分隔符?

我尝试了下面链接中给出的 SimpleItemDecorator 类,但没有给我预期的结果:

https://stackoverflow.com/a/41547052

【问题讨论】:

  • 添加到recyclerview item的底部
  • 添加什么?左侧的分隔线之间有一个间隙。我将不胜感激定制它的一些帮助。如果您知道如何,请添加它以回答。如果这是重复的问题,请发布原始链接。
  • 你尝试了什么?给我们看
  • 向项目添加可绘制对象
  • 我已经添加了一些细节,如果你们觉得还不够,请告诉我

标签: android android-layout android-recyclerview


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_60sdp"
    android:background="@color/white">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/padding_small">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/msgimage"
            android:layout_width="@dimen/_50sdp"
            android:layout_height="@dimen/_50sdp"
            android:layout_alignParentStart="true"
            android:src="@drawable/adpost_placeholder" />


        <LinearLayout
            android:id="@+id/textsec"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_toEndOf="@+id/msgimage"
            android:layout_toStartOf="@+id/follosec"
            android:orientation="vertical">


            <com.codinghands.pistachio.Custom.MyTextViewRegular
                android:id="@+id/msgusername"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_extra_very_small"
                android:layout_marginTop="@dimen/margin_small"
                android:text="name"
                android:textColor="@color/text_black"
                android:textSize="@dimen/text_small"
                android:textStyle="bold" />

            <com.codinghands.pistachio.Custom.MyTextViewRegular
                android:id="@+id/msgfullname"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin_extra_very_small"
                android:paddingEnd="@dimen/padding_small"
                android:text="name"
                android:textColor="@color/text_lightgrey"
                android:textSize="@dimen/text_very_small" />


        </LinearLayout>


    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginStart="@dimen/_60sdp"
        android:layout_marginEnd="@dimen/padding_small"
        android:layout_alignParentBottom="true"
        android:background="#000000" />
</RelativeLayout>


**it will be something like this change margin,padding,color and textview to your need. use it as item in recyclerview **

检查它是否在 bindholder 中的最后一个药水并隐藏视图以删除最后一个位置的项目分隔符

【讨论】:

  • 这是个好主意,但我不想在列表的最后一个元素中看到分隔符。在上面的解决方案中你可以看到它。
  • 检查它的最后一个药水是否在 bindholder 中并隐藏它
  • 是的,我自己也得出了这个结论。编辑答案并添加该部分。我会接受它作为解决方案。感谢您的宝贵时间。
【解决方案2】:

我只是将它添加到我的 recyclerview 的膨胀文件中。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">

<View
    android:id="@+id/divider"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/uvv_light_gray"
    android:layout_marginEnd="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginStart="10dp"
    android:layout_marginLeft="10dp"/>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/custom_ripple"
    android:padding="10dp">

    ....
    ....

</RelativeLayout>

【讨论】:

    猜你喜欢
    • 2019-09-03
    • 2015-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    相关资源
    最近更新 更多