-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Usage
代码家 edited this page Aug 25, 2014
·
9 revisions
- LEFT
- RIGHT
- TOP
- BOTTOM
Create a SwipeLayout
.
There are some rules you should obey, when you are creating SwipeLayout
.
- The
SwipeLayout
can only have 2 children. - The 2 children should all be an instance of
ViewGroup
, e.gLinearLayout
,RelativeLayout
,GridLayout
. - The first child is the BottomView, the second child is the SurfaceView.
-
SwipeLayout
layout_height
should be a specific value instead ofmatch_parent
orwrap_content
.
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.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 master the basic usage of SwipeLayout
, while, if you want to use SwipeLayout
in ListView
, GridView
, or some other class which extends from AdapterView
, you need to learn how to use SwipeAdapter
.