In a FrameLayout there's a child TextView which can be dragged, but the method onViewReleased and onViewPositionChanged don't work properly(scroll back to the original place) when I try to change text or margin of this TextView while it is scrolling.I'm not sure if I use it right or there's something I should know about.
part of the code:
ViewDragHelper.Callback callback = new ViewDragHelper.Callback() {
@Override public boolean tryCaptureView(View child, int pointerId) {
return child == indicator;
}
@Override public int clampViewPositionHorizontal(View child, int left, int dx) {
final int leftBound = getPaddingLeft();
final int rightBound = getWidth() - indicator.getWidth() - leftBound;
final int newLeft = Math.min(Math.max(left, leftBound), rightBound);
return newLeft;
}
@Override public void onViewReleased(View releasedChild, float xvel, float yvel) {
if (indicator == releasedChild) {
if (releasedChild.getLeft() > ((endPointX - startPointX) / 2)) {
textView.setText("FRUSTRATION");
helper.settleCapturedViewAt(endPointX, getPaddingTop());
} else {
textView.setText("INDICATOR");
helper.settleCapturedViewAt(startPointX, getPaddingTop());
}
invalidate();
}
}
};