-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Usage
Prat edited this page Apr 18, 2015
·
9 revisions
- LEFT
- RIGHT
- TOP
- BOTTOM
Create a SwipeLayout.
There are some rules you should obey, when you are creating SwipeLayout.
- The
SwipeLayoutcan only have 2 children. - The 2 children should all be an instance of
ViewGroup, e.g.LinearLayout,RelativeLayout,GridLayout. - 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>Get SwipeLayout instance.
SwipeLayout swipeLayout = (SwipeLayout)findViewById(R.id.sample1);
//set show mode.
swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
//set drag edge.
swipeLayout.addDrag(SwipeLayout.DragEdge.Left, findViewById(R.id.bottom_wrapper));
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 onStartOpen(SwipeLayout layout) {
}
@Override
public void onOpen(SwipeLayout layout) {
//when the BottomView totally show.
}
@Override
public void onStartClose(SwipeLayout layout) {
}
@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.


