视频聊天室源码,按住对话框右滑显示删除实现的相关代码
1.设计界面
界面导入 recycleview 的包
Friendweixin.xml:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp" //边距为 8dp
android:overScrollMode="never" //设置滑动到边缘时无效果模式
android:scrollbars="none" //滚动条隐藏
app:layout_constraintEnd_toEndOf="parent"
//结束时对其下一个 view 结束的位置
app:layout_constraintStart_toStartOf="parent"
//view1 起始位置对齐 view2 的起始位置
app:layout_constraintTop_toTopOf="parent" />
//view1 顶部对齐 view2 的顶部
</androidx.constraintlayout.widget.ConstraintLayout
Itemweixin.xml:
外层是垂直的 LinearLayout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_margin="8dp"
android:background="@drawable/common_bg"
android:orientation="vertical">
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp" />
</LinearLayout>
Itemtop.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/header_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#3E8841"
android:padding="10dp"
android:textColor="@android:color/white"
android:textSize="14sp"
tools:text="@string/app_name" />
2.适应器adapter
Myadapterweixin,java:
package com.example.myapplication1;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class myadapterweixin extends
RecyclerView.Adapter<myadapterweixin.swipeviewholder> implements
TouchHelperListener {
private List<String>list;
private Context context;
private View inflater;
public myadapterweixin(Context context, List<String> list) {
this.context=context;
this.list=list;
}
@Override
public swipeviewholder onCreateViewHolder(ViewGroup parent, int
viewType) {
inflater=
LayoutInflater.from(context).inflate(R.layout.itemweixin,parent,false
);
swipeviewholder swipeviewholder=new swipeviewholder(inflater);
return swipeviewholder;
}
@Override
public void onBindViewHolder(swipeviewholder holder, int
position) {
holder.tvContent.setText(list.get(position));
}
@Override
public int getItemCount() {return list.size();}
@Override
public void OnItemDismiss(int position) {
if (position < 0 || position > getItemCount()) {
return;
}
list.remove(position);
notifyItemRemoved(position);
if (position != list.size()) {
notifyItemRangeChanged(position, list.size() -
position);
}
}
public class swipeviewholder extends RecyclerView.ViewHolder{
TextView tvContent;
public swipeviewholder(View itemView) {
super(itemView);
tvContent = itemView.findViewById(R.id.content);
}
}
}
以上就是 视频聊天室源码,按住对话框右滑显示删除实现的相关代码,更多内容欢迎关注之后的文章