我有一个底部对话框,并在布局中存在EditText。 EditText是多行,最大行是3.我把:
commentET.setMovementMethod(new ScrollingMovementMethod());
commentET.setScroller(new Scroller(bottomSheetBlock.getContext()));
commentET.setVerticalScrollBarEnabled(true);
但是当用户将开始垂直滚动EditText文本时,BottomSheetBehavior拦截事件和EditText将不会垂直滚动。
有谁知道如何解决这个问题?
这是一个简单的方法。
yourEditTextInsideBottomSheet.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
v.getParent().requestDisallowInterceptTouchEvent(true);
switch (event.getAction() & MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
我用以下方法解决了这个问题:
BottomSheetBehavior
:
public class WABottomSheetBehavior<V extends View> extends BottomSheetBehavior<V> {
private boolean mAllowUserDragging = true;
public WABottomSheetBehavior() {
super();
}
public WABottomSheetBehavior(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setAllowUserDragging(boolean allowUserDragging) {
mAllowUserDragging = allowUserDragging;
}
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
if (!mAllowUserDragging) {
return false;
}
return super.onInterceptTouchEvent(parent, child, event);
}
}
EditText
的触摸事件,当用户触摸EditText
区域时,我将通过调用方法setAllowUserDragging
禁用处理事件:
commentET.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (v.getId() == R.id.commentET) {
botSheetBehavior.setAllowUserDragging(false);
return false;
}
return true;
}
});