Skip to content
CCMDevel edited this page Sep 29, 2014 · 9 revisions

Usage

Basic:

Show Mode

1. LayDown

2. PullOut

Drag edge:

  • LEFT
  • RIGHT
  • TOP
  • BOTTOM

Step-1

Create a SwipeLayout.

There are some rules you should obey, when you are creating SwipeLayout.

  1. The SwipeLayout can only have 2 children.
  2. The 2 children should all be an instance of ViewGroup, e.g. LinearLayout, RelativeLayout, GridLayout.
  3. The first child is the BottomView, the second child is the SurfaceView.

For example:

<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="80dp">
    <!-- Bottom View Start-->
     <LinearLayout
        android:background="#66ddff00"
        android:id="@+id/bottom_wrapper"
        android:layout_width="160dp"
        android:weightSum="1"
        android:layout_height="match_parent">
        <!--What you want to show-->
    </LinearLayout>
    <!-- Bottom View End-->

    <!-- Surface View Start -->
     <LinearLayout
        android:padding="10dp"
        android:background="#ffffff"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <!--What you want to show in SurfaceView-->
    </LinearLayout>
    <!-- Surface View End -->
</com.daimajia.swipe.SwipeLayout>

Step-2

Get SwipeLayout instance.

SwipeLayout swipeLayout =  (SwipeLayout)findViewById(R.id.sample1);

//set show mode.
swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);

//set drag edge.
swipeLayout.setDragEdge(SwipeLayout.DragEdge.Left);

swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
            @Override
            public void onClose(SwipeLayout layout) {
                //when the SurfaceView totally cover the BottomView.
            }

            @Override
            public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
               //you are swiping.
            }

            @Override
            public void onOpen(SwipeLayout layout) {
               //when the BottomView totally show.
            }

            @Override
            public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
               //when user's hand released.
            }
        });

Well done! You have mastered the basic usage of SwipeLayout. If you want to use SwipeLayout in ListView, GridView, or some other class which extends from AdapterView, you should learn how to use SwipeAdapter.

Go for SwipeAdater!

Clone this wiki locally