先上效果图:
一、创建xml
1.android_ceshi_activity
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/rvAndroid" android:layout_width="match_parent" android:layout_height="match_parent" android:overScrollMode="never" android:paddingBottom="12dp" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" tools:itemCount="4" tools:listitem="@layout/android_ceshi_item" /> </LinearLayout>
2.android_ceshi_item
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/tvName" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:minHeight="46dp" android:padding="10dp" android:text="测试灯虎试试看" android:textColor="@color/black" android:textSize="@dimen/sp_14" /> <TextView android:id="@+id/btnPinglun" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:minHeight="46dp" android:padding="10dp" android:layout_alignParentEnd="true" android:text="评论" android:textColor="@color/black" android:textSize="@dimen/sp_14" /> </RelativeLayout> <com.june.wt.commentview.CommentsView android:id="@+id/commentView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginStart="15dp" android:layout_marginEnd="15dp"/> <TextView android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/gray" /> </LinearLayout>
二、创建评论相关的实体类
1.CeshiBean
package com.june.wt.commentview class CeshiBean { var name = "" var commentList: List<CommentsBean>? = null }
2.CommentsBean
package com.june.wt.commentview; import java.io.Serializable; public class CommentsBean implements Serializable { // 评论ID private String id; // 园地ID private String scopeId; // 发布评论人的ID private String userId; // 回复人ID() private String userCodeId; // 评论内容 private String commentCount; // 发布评论人的 姓名 private String createBy; // 回复人的 姓名 private String updateBy; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getScopeId() { return scopeId; } public void setScopeId(String sc