如何创建WhatsApp中的项目分隔符?

问题描述 投票:-4回答:2

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

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

https://stackoverflow.com/a/41547052

enter image description here

android android-layout android-recyclerview
2个回答
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中的lastpotion并隐藏视图以删除lastposition的项目分隔符


0
投票

我只是将它添加到我的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>

© www.soinside.com 2019 - 2024. All rights reserved.