Skip to content

LuodiJackShen/ScrollDelete

Repository files navigation

ScrollDelete

Download
博客地址
仿qq滑动删除-已经处理了滑动冲突,使用简单。

效果图

效果图

使用

  1.  加入依赖
        compile 'jack.view:scrolldel:1.0.1'
  1.  在布局文件里引入
        <jack.view.ScrollDeleteLayout
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_marginTop="20dp"
                android:background="@android:color/darker_gray"
                app:from_left="false">

                <TextView
                    android:id="@+id/show_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@android:color/holo_orange_dark"
                    android:gravity="center"
                    android:text="@string/app_name" />

                ...其他控件

            </jack.view.ScrollDeleteLayout>

2.ViewHolder实现OnExtendListener接口,并设置监听,demo:

        class ItemViewHolder extends RecyclerView.ViewHolder implements ScrollDeleteLayout.OnExtendListener {
            TextView tv;
            Button btn1;
            Button btn2;
            ScrollDeleteLayout layout;

            ItemViewHolder(View itemView) {
                super(itemView);
                layout = (ScrollDeleteLayout) itemView;
                /***
                 * 设置展开监听器.
                 */
                layout.setOnExtendListener(this);

                tv = itemView.findViewById(R.id.show_view);
                btn1 = itemView.findViewById(R.id.delete);
                btn2 = itemView.findViewById(R.id.collect);
                btn1.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(MainActivity.this, "delete", Toast.LENGTH_SHORT)
                                .show();
                    }
                });
                btn2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Toast.makeText(MainActivity.this, "collect", Toast.LENGTH_SHORT)
                                .show();
                    }
                });
            }

            void bindView(int position) {
                tv.setText(String.valueOf(position));
            }

            /***
            * 实现监听器
            */
            @Override
            public void onExtend(ScrollDeleteLayout layout) {
                    if (mDeleteLayout != null) {
                        mDeleteLayout.shrink();
                    }
                    mDeleteLayout = null;
                    mDeleteLayout = layout;
            }
        }

3.ScrollDeleteLayout父布局设置滑动监听,demo:

        mRv.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (mDeleteLayout != null) {
                    /***
                     * 当外面的布局滑动时,使ScrollDeleteLayout收缩布局。
                     */
                    mDeleteLayout.shrink();
                }
            }
        });

Demo

app下的MainActivity

最后

欢迎在issue中批评指教,欢迎star,欢迎访问 我的博客

License

Copyright 2018 Luodi Jack Shen

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

仿qq滑动删除-已经处理了滑动冲突

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages