ASwipeLayout一個強大的側滑菜單控件

前言

該控件的優勢:android

  • 1.不管是在RecyclerView,ListView,仍是LinearLayout等,只要是ViewGroup用該控件都能實現側滑。
  • 2.控件的手勢滑動衝突已解決,不會出現嵌套到ScrollView等控件出現滑動不流暢的狀況
  • 3.控件使用簡單,只須要在xml外套一層該控件就行了,秒接入
  • 4.點擊事件很方便,原來什麼寫法就什麼寫法

APK下載地址

1.效果圖

雙列

2.使用方式其實挺簡單的,在設計的時候,就是想着怎麼簡單怎麼來

2.1引入庫:

Step 1. Add it in your root build.gradle at the end of repositories:
    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
Step 2. Add the dependency

    dependencies {
            implementation 'com.github.WelliJohn:ASwipeLayout:0.0.2'
    }

2.2在須要側滑的佈局的根佈局中添加下面這段代碼,注意註釋的地方纔是能夠定製的:

<?xml version="1.0" encoding="utf-8"?>
<wellijohn.org.swipevg.ASwipeLayout 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"
    android:orientation="horizontal">


    <LinearLayout
        android:id="@+id/ll_content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFFFF"
        android:orientation="horizontal">

        //在這裏是實現你的主item的東西,根據大家的項目隨便添加
    </LinearLayout>

    <LinearLayout
        android:id="@+id/right_menu_content"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">
 
        //在這裏是實現右側的菜單,根據大家的項目隨便添加
    </LinearLayout>


</wellijohn.org.swipevg.SwipeLayout>

注意在這裏ll_content,right_menu_content是必定要的,這個id對應的佈局不要本身去改變,之後有須要會放開,目前的話,通常的狀況大家只須要定製主item的內容和右側菜單欄了,在這裏我也省去了定義一些額外的自定義view了,單純就是用id,來區分主item和右側的菜單。git

3.由於RecyclerView中有複用Item的狀況,針對這種狀況的解決方案

由於item複用會使得當咱們滑出某個menu的時候,再進行RecyclerView的上下滑動時,會使得其餘的Item也滑出了menu,這就是item複用致使了佈局錯亂,因此針對這類型的問題的話,我在這裏已經提供了OnSwipeStateChangeListener接口,在這裏大家能夠記錄下滑動的狀態,在onBindViewHolder方法裏面,根據狀態來設定Item是打開menu仍是關閉menu:github

@Override
    public void onBindViewHolder(ViewHolder holder, int position) {

        final Person person = mDatas.get(position);
        holder.scrollDelLl.setOpen(person.isOpen());

        holder.scrollDelLl.setOnSwipeStateChangeListener(new OnSwipeStateChangeListener() {
            @Override
            public void onSwipeStateChange(boolean open) {
                person.setOpen(open);
            }
        });

    }

如上代碼就能夠解決Item複用致使佈局錯亂的問題了(粑粑不再用擔憂RecyclerView複用的問題了)。app

4.若是大家在項目使用的過程當中,有心得需求或者是bug的話,能夠在github上提大家的需求或者issue

5.代碼已上傳github,ASwipeLayout

相關文章
相關標籤/搜索