Fah*_*him 5 android android-support-library android-support-design bottom-sheet
由于我的声誉点很低,我无法发表评论。所以我要扩展这个问题: 禁用用户在BottomSheet上拖动
Ray W 提供的解决方案有效,但现在它通过在父视图(CoordinatorLayout)上滑动和拖动来扩展。
在该图像中,如果我拖动“不需要的拖动区域”,BottomSheet 会向上滑动。如何过滤或停止不需要的视图上的触摸事件?
将Ray W 解决方案中的 onInterceptTouchEvent 函数返回值更改为:
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
return super.onInterceptTouchEvent(parent, child, event) && mAllowUserDragging;
}
Run Code Online (Sandbox Code Playgroud)
另一件事,如果你在 BottomSheetLayout 中有一个 ListView,那么滚动 ListView 中的项目会将 BottomSheetBehavior 状态从“STATE_EXPANDED”更改为“STATE_DRAGGING”。示例代码片段:
@Override
public void onBackPressed() {
if(isBottomViewOpen){ // set this bool in behavior callback
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}else {
super.onBackPressed();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10515 次 |
| 最近记录: |