Skip to content

Commit 4d66856

Browse files
committed
Merge pull request #57 from rahulrj/master
Added horizontal and vertical offset for swiping
2 parents f3b50c4 + ce1eb70 commit 4d66856

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

demo/src/main/res/layout/listview_item.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
android:layout_width="match_parent"
44
android:layout_height="match_parent">
55
<com.daimajia.swipe.SwipeLayout
6+
xmlns:swipe="http://schemas.android.com/apk/res-auto"
67
android:id="@+id/swipe"
78
android:layout_width="match_parent"
89
android:layout_height="wrap_content"
10+
swipe:horizontalSwipeOffset="25dp"
911
>
1012

1113
<LinearLayout

library/src/main/java/com/daimajia/swipe/SwipeLayout.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class SwipeLayout extends FrameLayout {
3030
private DragEdge mDragEdge;
3131
private ShowMode mShowMode;
3232

33+
private float mHorizontalSwipeOffset;
34+
private float mVerticalSwipeOffset;
35+
3336
private List<SwipeListener> mSwipeListeners = new ArrayList<SwipeListener>();
3437
private List<SwipeDenier> mSwipeDeniers = new ArrayList<SwipeDenier>();
3538
private Map<View, ArrayList<OnRevealListener>> mRevealListeners = new HashMap<View, ArrayList<OnRevealListener>>();
@@ -65,6 +68,8 @@ public SwipeLayout(Context context, AttributeSet attrs, int defStyle) {
6568

6669
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeLayout);
6770
int ordinal = a.getInt(R.styleable.SwipeLayout_drag_edge, DragEdge.Right.ordinal());
71+
mHorizontalSwipeOffset =a.getDimension(R.styleable.SwipeLayout_horizontalSwipeOffset,0);
72+
mVerticalSwipeOffset =a.getDimension(R.styleable.SwipeLayout_verticalSwipeOffset,0);
6873
mDragEdge = DragEdge.values()[ordinal];
6974
ordinal = a.getInt(R.styleable.SwipeLayout_show_mode, ShowMode.PullOut.ordinal());
7075
mShowMode = ShowMode.values()[ordinal];
@@ -657,9 +662,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
657662
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
658663

659664
if(mDragEdge == DragEdge.Left || mDragEdge == DragEdge.Right)
660-
mDragDistance = getBottomView().getMeasuredWidth();
665+
mDragDistance = getBottomView().getMeasuredWidth()-dp2px(mHorizontalSwipeOffset);
661666
else
662-
mDragDistance = getBottomView().getMeasuredHeight();
667+
mDragDistance = getBottomView().getMeasuredHeight()-dp2px(mVerticalSwipeOffset);
663668
}
664669

665670
private boolean mTouchConsumedByChild = false;

library/src/main/res/values/attrs.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
<enum name="top" value="2"/>
88
<enum name="bottom" value="3"/>
99
</attr>
10+
<attr name="horizontalSwipeOffset" format="dimension"/>
11+
<attr name="verticalSwipeOffset" format="dimension"/>
1012
<attr name="show_mode" format="enum">
1113
<enum name="lay_down" value="0"/>
1214
<enum name="pull_out" value="1"/>

0 commit comments

Comments
 (0)