我是靠谱客的博主 健忘黄蜂,最近开发中收集的这篇文章主要介绍AndroidSwipeLayout 滑动功能。,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

一。依赖

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    区分颜色理解不同区域

<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>

三.数据

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;
    }
}

四.适配器

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

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);
}



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

 //动画库
    compile 'com.daimajia.easing:library:2.0@aar'
    compile 'com.daimajia.androidanimations:library:2.3@aar'


@Override
            public void onOpen(SwipeLayout layout) {
                //底部View完全展示
                YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(R.id.imageDelete));
            }

 

最后

以上就是健忘黄蜂为你收集整理的AndroidSwipeLayout 滑动功能。的全部内容,希望文章能够帮你解决AndroidSwipeLayout 滑动功能。所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部