1
在FrameLayout中有一個可以拖動的子TextView,但是當我嘗試更改文本或此邊距時,onViewReleased和onViewPositionChanged方法無法正常工作(回滾到原始位置) TextView,而它是滾動。我不確定我是否正確使用它,或者有些事情我應該知道。代碼ViewDragHelper無法正常工作
部分:
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();
}
}
};