安卓swipeLayout雙向側滑控件,比qq側滑刪除效果更牛叉

安卓swipeLayout雙向側滑控件

標籤(空格分隔): 安卓 雙向側滑


說明:

可以實現橫向的雙向滑動和縱向的豎向滑動,使用非常方便,只需要在佈局中指定leftview,contentview和rightview即可實現左右滑動效果,使用起來跟普通控件一樣簡單.
git地址,點擊跳轉
此處輸入圖片的描述

1.用法

1.引用

 compile 'com.z:SwipeLayout:1.0.0'

2.佈局中使用

該控件繼承自framlayout,必須要有三個自佈局,一個是左邊view,一個是中間view一個是右邊view,使用中要指定view的id,自佈局不用區分先後順序.
注意一下三個屬性的設置:
app_contentView_id=”@+id/middle”

    app_leftView_id="@+id/left"

    app_rightView_id="@+id/right"
<--如果用實現豎向的雙向滑動,要用SwipeVertical佈局即可-->
    <z.swipelibrary.SwipeHorizontal

        android:id="@+id/swiper"

        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="50dp"
        app:app_contentView_id="@+id/middle"
        app:app_leftView_id="@+id/left"
        app:app_rightView_id="@+id/right">

        <LinearLayout

            android:id="@id/left"
            android:layout_width="wrap_content"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/dismiss"
                android:layout_width="100dp"
                android:layout_height="50dp"
                android:background="#0f0"
                android:text="left12345678901234" />

            <TextView
                android:id="@+id/tv2"
                android:layout_width="100dp"
                android:layout_height="50dp"
                android:background="#ff0"
                android:text="left12345678901234" />

        </LinearLayout>

        <LinearLayout
            android:id="@id/right"
            android:layout_width="200dp"
            android:layout_height="match_parent">

            <TextView

                android:layout_width="100dp"
                android:layout_height="50dp"
                android:background="#5f00"
                android:text="right12345678901234" />

            <TextView

                android:layout_width="100dp"
                android:layout_height="50dp"
                android:background="#f00"
                android:text="right12345678901234" />

        </LinearLayout>

        <LinearLayout
            android:id="@id/middle"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="200dp"
                android:layout_height="50dp"
                android:background="#500f"
                android:text="content" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="#00f"
                android:text="content" />

        </LinearLayout>

    </z.swipelibrary.SwipeHorizontal>

3.直接找到佈局中的對應的控件,隨意使用

mLeftLinearLayout = (LinearLayout) findViewById(R.id.left);
        mRightLinearLayout = (LinearLayout) findViewById(R.id.right);
        mMiddleLinearLayout = (LinearLayout) findViewById(R.id.middle);
        mSwiperSwipeHorizontal = (SwipeHorizontal) findViewById(R.id.swiper);

4.其他方法的使用

//獲取滑動速度閾值
    public double getSPEED_LIMIT() {
        return SPEED_LIMIT;
    }
//設置滑動素的閾值
    public void setSPEED_LIMIT(double SPEED_LIMIT) {
        this.SPEED_LIMIT = SPEED_LIMIT;
    }
//左邊是否打開
    public boolean isLeftOpen() {
        return isLeftOpen;
    }
//右邊是否打開
    public boolean isRrightOpen() {
        return isRrightOpen;
    }
    //打開右邊
 public void openRight()
 //打開左邊
 public void openLeft()
 //關閉,無論那邊是打開的都可以關閉
 public void close()
 //設置打開關閉的監聽器
public void setOnDragActionListener(OnDragActionListener listener)

5.豎向的雙向滑動實現示例

跟橫向的非常相像,只是把leftview換成topview,rightview換成了bottomview而已,打開方法是openTop()…..

    <z.swipelibrary.SwipeVertical
        android:id="@+id/swiper1"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_marginTop="50dp"
        app:app_BottomView_id="@+id/bottom"
        app:app_MiddleView_id="@+id/middle1"
        app:app_TopView_id="@+id/top">

        <LinearLayout
            android:id="@id/top"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:id="@+id/dismiss1"
                android:layout_width="100dp"
                android:layout_height="50dp"
                android:background="#0f0"
                android:text="left12345678901234" />

            <TextView
                android:id="@+id/tv3"
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="#ff0"
                android:text="left12345678901234" />

        </LinearLayout>

        <LinearLayout
            android:id="@id/bottom"
            android:layout_width="match_parent"
            android:layout_height="50dp">

            <TextView
                android:layout_width="100dp"
                android:layout_height="50dp"
                android:background="#5f00"
                android:text="right12345678901234" />

            <TextView

                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="#f00"
                android:text="right12345678901234" />

        </LinearLayout>

        <LinearLayout
            android:id="@id/middle1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:layout_width="200dp"
                android:layout_height="50dp"
                android:background="#500f"
                android:text="content" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:background="#50ff"
                android:text="content" />

        </LinearLayout>

    </z.swipelibrary.SwipeVertical>

6.已知bug和注意事項

1.bug:橫向滑動的不支持設置左右padding值,縱向滑動不支持設置上下padding值,如果設置不會起到任何作用,
2.注意:此控件中有三個直接的子控件,必須設置,如果要實現只打開一邊等功能,直接把另一邊的view寬度或者高度設置爲0即可,

2.原理

使用viewdraghelper實現

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章