我是靠谱客的博主 健忘黄蜂,这篇文章主要介绍AndroidSwipeLayout 滑动功能。,现在分享给大家,希望可以做个参考。

这里演示一个例子。RecyclerView的Item 滑动功能。

复制代码
1
2
一。依赖

复制代码
1
2
3
4
5
compile 'com.daimajia.swipelayout:library:1.2.0@aar' //RecyclerView 快速适配器 compile 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.30' //design26.1.0 implementation 'com.android.support:design:26.1.0'

二。item.xml    区分颜色理解不同区域

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swipeLayout" android:layout_width="match_parent" android:layout_height="80dp"> <!-- Bottom View Start--> <LinearLayout android:id="@+id/bottom_wrapper" android:layout_width="160dp" android:layout_height="match_parent" android:background="#66ddff00" android:orientation="horizontal" android:weightSum="1"> <!--What you want to show--> <ImageView android:id="@+id/imageDelete" android:src="@mipmap/ic_launcher" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> <!-- Bottom View End--> <!-- Surface View Start --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:padding="10dp"> <!--What you want to show in SurfaceView--> <TextView android:id="@+id/tvTitle" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> <!-- Surface View End --> </com.daimajia.swipe.SwipeLayout>

三.数据

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public class DataBean { private String title; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public DataBean(String title) { this.title = title; } }

四.适配器

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class MyAdapter extends BaseQuickAdapter<DataBean, BaseViewHolder> { public MyAdapter(int layoutResId, @Nullable List<DataBean> data) { super(layoutResId, data); } @Override protected void convert(BaseViewHolder helper, DataBean item) { helper.setText(R.id.tvTitle,item.getTitle()); SwipeLayout swipeLayout = helper.getView(R.id.swipeLayout); helper.addOnClickListener(R.id.imageDelete); //set show mode. swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown); //添加拖边缘。(如果底部视图布局重力的属性,这条线是多余的) swipeLayout.addDrag(SwipeLayout.DragEdge.Left, helper.getView(R.id.bottom_wrapper)); swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() { @Override public void onClose(SwipeLayout layout) { //当表面完全覆盖底部视图。 } @Override public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) { //正在滑动 } @Override public void onStartOpen(SwipeLayout layout) { } @Override public void onOpen(SwipeLayout layout) { //底部View完全展示 } @Override public void onStartClose(SwipeLayout layout) { } @Override public void onHandRelease(SwipeLayout layout, float xvel, float yvel) { //手离开屏幕 } }); } }

五.MainActivity

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
private RecyclerView recycler; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); final List<DataBean> datas = new ArrayList<>(); DataBean dataBean1 = new DataBean("标题1"); DataBean dataBean2 = new DataBean("标题2"); DataBean dataBean3 = new DataBean("标题3"); DataBean dataBean4 = new DataBean("标题4"); DataBean dataBean5 = new DataBean("标题5"); datas.add(dataBean1); datas.add(dataBean2); datas.add(dataBean3); datas.add(dataBean4); datas.add(dataBean5); recycler.setLayoutManager(new LinearLayoutManager(this)); final MyAdapter myAdapter = new MyAdapter(R.layout.item, datas); recycler.setAdapter(myAdapter); myAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() { @Override public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) { switch (view.getId()) { case R.id.imageDelete: datas.remove(position); myAdapter.notifyDataSetChanged(); break; default: break; } } }); } private void initView() { recycler = (RecyclerView) findViewById(R.id.recycler); }

//因为条目拖动会有小重叠 添加一个动画  也是作者写好的一个动画库

复制代码
1
2
3
//动画库 compile 'com.daimajia.easing:library:2.0@aar' compile 'com.daimajia.androidanimations:library:2.3@aar'


复制代码
1
2
3
4
5
@Override public void onOpen(SwipeLayout layout) { //底部View完全展示 YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.imageDelete)); }

复制代码
1

最后

以上就是健忘黄蜂最近收集整理的关于AndroidSwipeLayout 滑动功能。的全部内容,更多相关AndroidSwipeLayout内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(60)

评论列表共有 0 条评论

立即
投稿
返回
顶部