Skip to content

Commit dc0c1eb

Browse files
authored
Update README.md
1 parent ad282db commit dc0c1eb

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

README.md

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,13 @@ A version of [ViewDragHelper](https://developer.android.com/reference/android/su
77
# Usage
88
If you have ever used a `ViewDragHelper` before, you may have noticed that if you were to translate your views using View.setX() or View.setY(), your helper would no longer correctly allow you to drag the views. This library seeks to correct this. Usage is identical to `ViewDragHelper` usage
99
```java
10-
TranslationViewDragHelper viewDragHelper = TranslationViewDragHelper.create(
11-
viewGroup,
12-
1.0f,
13-
viewDragHelperCallback);
14-
15-
//Somewhere else...
16-
TranslationViewDragHelper.Callback mCallback = new TranslationViewDragHelper.Callback() {
10+
TranslationViewDragHelper.Callback callback = new TranslationViewDragHelper.Callback() {
1711
@Override
1812
public boolean tryCaptureView(View child, int pointerId) {
1913
//Any children can be captured
2014
return true;
2115
}
2216

23-
@Override
24-
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
25-
super.onViewPositionChanged(changedView, left, top, dx, dy);
26-
//Simply set the views translation to the new position
27-
changedView.setX(left);
28-
changedView.setY(top);
29-
}
30-
3117
@Override
3218
public int clampViewPositionHorizontal(View child, int left, int dx) {
3319
//allow full movement along horizontal axis
@@ -40,6 +26,11 @@ TranslationViewDragHelper.Callback mCallback = new TranslationViewDragHelper.Cal
4026
return top;
4127
}
4228
};
29+
30+
TranslationViewDragHelper viewDragHelper = TranslationViewDragHelper.create(
31+
viewGroup,
32+
1.0f,
33+
callback);
4334
```
4435
See the sample [custom view](https://github.com/Commit451/TranslationViewDragHelper/blob/master/app/src/main/java/com/commit451/betterviewdraghelper/sample/AllowsForDragFrameLayout.java) for a more complete example
4536

0 commit comments

Comments
 (0)