### 侧滑删除布局
参考链接:
[史上最简单,一步集成侧滑(删除)菜单,高仿QQ、IOS](https://blog.csdn.net/zxt0601/article/details/53157090)
[SwipeDelMenuLayout](https://github.com/mcxtzhang/SwipeDelMenuLayout)
![demo](demo.gif)
**使用方式:**
implementation 'com.hm.kof97:slidedeletelayout:1.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="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
```
**recyclerView item的布局文件**
```xml
<?xml version="1.0" encoding="utf-8"?>
<com.hm.slidedeletelayout.SlideDeleteLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:iosStyle="true"
app:leftSlide="true"
app:slideEnable="true">
<RelativeLayout
android:id="@+id/item_rl_content"
android:layout_width="match_parent"
android:layout_height="140dp"
android:background="@android:color/white">
<ImageView
android:id="@+id/item_image_book"
android:layout_width="70dp"
android:layout_height="90dp"
android:layout_centerVertical="true"
android:layout_marginLeft="16dp"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginTop="16dp"
android:layout_toRightOf="@+id/item_image_book">
<TextView
android:id="@+id/item_text_book_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="14dp"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:maxLines="1"
android:text="平凡的世界路遥"
android:textColor="@color/colorAccent"
android:textSize="12sp"/>
<TextView
android:id="@+id/item_text_book_isbn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/item_text_book_name"
android:layout_marginRight="14dp"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:gravity="left|center_vertical"
android:maxLines="1"
android:text="ISBN:100086"
android:textColor="@color/colorAccent"
android:textSize="12sp"/>
</RelativeLayout>
</RelativeLayout>
<TextView
android:id="@+id/item_text_remove"
android:layout_width="80dp"
android:layout_height="140dp"
android:layout_toRightOf="@+id/item_ll_content"
android:gravity="center"
android:text="删除"
android:background="@color/colorPrimary"
android:textColor="@color/colorAccent"/>
</com.hm.slidedeletelayout.SlideDeleteLayout>
```
**自定义属性说明**
```
<!--是否可以通过滑动,显示删除菜单,默认true-->
<attr name="slideEnable" format="boolean"/>
<!--是否是ios方式的滑动方式,默认true-->
<attr name="iosStyle" format="boolean"/>
<!--标记是左滑还是右滑显示删除菜单,默认左滑显示删除菜单-->
<attr name="leftSlide" format="boolean"/>
```
**MainActivity代码**
```java
public class MainActivity extends AppCompatActivity {
public static final String TAG = MainActivity.class.getSimpleName();
private RecyclerView recyclerView;
private List<String> stringList;
private RvAdapter adapter;
private LinearLayoutManager layoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recycler_view);
stringList = new ArrayList<>();
for (int i = 0; i < 30; i++) {
stringList.add("string" + i);
}
adapter = new RvAdapter(this, stringList);
adapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Toast.makeText(MainActivity.this, "position=" + position, Toast.LENGTH_SHORT).show();
}
});
adapter.setOnItemDeleteListener(new OnItemDeleteListener() {
@Override
public void onItemDelete(int position) {
stringList.remove(position);
adapter.notifyItemRemoved(position);
}
});
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
}
class RvAdapter extends RecyclerView.Adapter<RvAdapter.VH> {
private Context context;
private List<String> stringList;
private OnItemClickListener onItemClickListener;
private OnItemDeleteListener onItemDeleteListener;
public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
this.onItemClickListener = onItemClickListener;
}
public void setOnItemDeleteListener(OnItemDeleteListener onItemDeleteListener) {
this.onItemDeleteListener = onItemDeleteListener;
}
public RvAdapter(Context context, List<String> stringList) {
this.context = context;
this.stringList = stringList;
}
@Override
public VH onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.item_slide_delete, parent, false);
return new VH(view);
}
@Override
public void onBindViewHolder(final VH holder, final int position) {
if (onItemClickListener != null) {
holder.itemRlContent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.e(TAG, "onClick: position=" + position);
onItemClickListener.onItemClick(v, holder.getAdapterPosition());
}
});
}
if (onItemDeleteListener != null) {
holder.itemTextRemove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onItemDeleteListener.onItemDelete(holder.getAdapterPosition());
}
});
}
holder.itemImageBook.setImageResource(R.mipmap.ic_launcher);
holder.itemTextBookIsbn.setText(stringList.get(position));
}
@Override
public int getItemCount() {
return stringList.size();
}
class VH extends RecyclerView.ViewHolder {
private ImageView itemImageBook;
private TextView itemTextBookName;
private RelativeLayout itemRlContent;
private TextView itemTextBookIsbn;
private TextView itemTextRemove;
public VH(View itemView) {
supe
没有合适的资源?快使用搜索试试~ 我知道了~
RecyclerView之添加头部、尾部和左滑显示删除按钮并删除Item
共1780个文件
class:658个
flat:496个
dex:190个
4星 · 超过85%的资源 需积分: 47 37 下载量 150 浏览量
2018-08-17
12:13:17
上传
评论 1
收藏 16.73MB ZIP 举报
温馨提示
RecyclerView之添加头部、尾部和左滑显示删除按钮并删除Item;有添加头部的左右删除Item,有添加头部和尾部的左滑删除item.
资源推荐
资源详情
资源评论
收起资源包目录
RecyclerView之添加头部、尾部和左滑显示删除按钮并删除Item (1780个子文件)
0A9Zxg0DlHyOIyBYPKhx4MBATxo= 9KB
0A9Zxg0DlHyOIyBYPKhx4MBATxo= 9KB
6n84Pr5T2rPCjJV5DxF+ur561Io= 375KB
6n84Pr5T2rPCjJV5DxF+ur561Io= 375KB
8CVxnJ57ev35F9l9xiXrhihLcHU= 7KB
8CVxnJ57ev35F9l9xiXrhihLcHU= 7KB
a_gOK9Gkt2MV+ed3M_A2H81ODaY= 25KB
a_gOK9Gkt2MV+ed3M_A2H81ODaY= 25KB
amn2RYYw7TNb2uYpFQms7qi8Ens= 284KB
amn2RYYw7TNb2uYpFQms7qi8Ens= 284KB
resources-debug.ap_ 405KB
resources-debug.ir.ap_ 403KB
dependencies.apk 1.05MB
app-debug.apk 456KB
slice_5.apk 58KB
slice_2.apk 40KB
slice_3.apk 13KB
slice_7.apk 11KB
slice_0.apk 11KB
slice_9.apk 10KB
slice_8.apk 10KB
slice_1.apk 7KB
slice_4.apk 7KB
slice_6.apk 7KB
aPRTSv7OXPRTJEMsEgZWqlL+wwo= 8KB
aPRTSv7OXPRTJEMsEgZWqlL+wwo= 8KB
gradlew.bat 2KB
taskHistory.bin 1.62MB
classAnalysis.bin 818KB
taskHistory.bin 693KB
jarAnalysis.bin 293KB
fileHashes.bin 283KB
outputFiles.bin 21KB
taskJars.bin 21KB
resourceHashesCache.bin 19KB
last-build.bin 1B
cBkAcI56SUmChJhzvtGBQVbqDK8= 9KB
cBkAcI56SUmChJhzvtGBQVbqDK8= 9KB
AddHeaderOrFooterActivity.class 36KB
AddHeaderOrFooterActivity.class 36KB
MainActivity.class 36KB
MainActivity.class 36KB
R$styleable.class 36KB
R$styleable.class 36KB
R$styleable.class 36KB
R$styleable.class 36KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 24KB
R$styleable.class 24KB
R$styleable.class 24KB
R$styleable.class 24KB
R$styleable.class 23KB
R$styleable.class 23KB
R$styleable.class 23KB
R$styleable.class 23KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 21KB
R$style.class 20KB
R$style.class 20KB
R$style.class 20KB
R$style.class 20KB
R$attr.class 14KB
R$attr.class 14KB
R$attr.class 14KB
R$attr.class 14KB
R$attr.class 11KB
R$attr.class 11KB
R$attr.class 11KB
R$attr.class 11KB
R$attr.class 11KB
R$attr.class 11KB
R$attr.class 11KB
R$attr.class 11KB
R$styleable.class 11KB
R$styleable.class 11KB
R$styleable.class 11KB
R$styleable.class 11KB
AddHeadAdapter.class 10KB
AddHeadAdapter.class 10KB
R$attr.class 10KB
R$attr.class 10KB
R$attr.class 10KB
R$attr.class 10KB
MainActivity$RvAdapter.class 9KB
MainActivity$RvAdapter.class 9KB
GridDividerItemDecoration.class 8KB
GridDividerItemDecoration.class 8KB
共 1780 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
- 弱机菜鸟2018-09-27不错了可以用来修改达到自己需要的样式
dawnZeng
- 粉丝: 36
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功