一app 下 build导入:
implementation 'com.android.support:recyclerview-v7:28.0.0'
//万能适配器
implementation 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.18'
//仿ios侧滑
implementation 'com.github.anzaizai:EasySwipeMenuLayout:1.1.4'
项目 build 下导入
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
二: 设置数据
1:导入布局文件
<?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"
android:id="@+id/ll_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical">
<com.guanaj.easyswipemenulibrary.EasySwipeMenuLayout
android:id="@+id/es"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentView="@+id/content"
app:leftMenuView="@+id/left"
app:rightMenuView="@+id/right">
<LinearLayout
android:id="@+id/left"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_dark"
android:orientation="horizontal"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:text="分享" />
</LinearLayout>
<LinearLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#cccccc"
android:orientation="vertical"
android:padding="20dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="内容区域" />
</LinearLayout>
<LinearLayout
android:id="@+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_red_light"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_bright"
android:clickable="true"
android:padding="20dp"
android:text="删除" />
<TextView
android:id="@+id/right_menu_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_dark"
android:clickable="true"
android:padding="20dp"
android:text="收藏" />
</LinearLayout>
</com.guanaj.easyswipemenulibrary.EasySwipeMenuLayout>
</LinearLayout>
private void initIView() {
recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
myAdapter = new MyAdapter(R.layout.item_rv_swipemenu, null);
recyclerView.setAdapter(myAdapter);
inflater = getLayoutInflater();
}
private void initIData() {
listData = new ArrayList<>();
for (int i = 0; i < 20; i++) {
listData.add("index is =" + i);
}
myAdapter.addData(listData);
myAdapter.notifyDataSetChanged();
}
2:adapter
public class MyAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
public MyAdapter(@LayoutRes int layoutResId, @Nullable List<String> data) {
super(layoutResId, data);
}
@Override
protected void convert(final BaseViewHolder helper, String item) {
helper.getView(R.id.right_menu_2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "收藏", Toast.LENGTH_SHORT).show();
//回复状态
EasySwipeMenuLayout easySwipeMenuLayout = helper.getView(R.id.es);
easySwipeMenuLayout.resetStatus();
}
});
helper.getView(R.id.content).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "setOnClickListener", Toast.LENGTH_SHORT).show();
}
});
}
}