如何使底部工作表 UI 的一部分不可拖动?
How can I make part of the BottomSheet UI not dragable?
底部sheet UI默认是dragable.That的就好了,我要的是可以拖动的。但是在底部的某个特定部分sheet,我想禁用拖动。
我正在使用底部 sheet 向用户显示收据。然后用户必须在收据上签名。 UI 中有一个可以接受签名的视图。但由于底部 sheet 是可拖动的,因此签署收据会摇动 sheet 的位置。当用户的触摸位于签名控件内时,有什么方法可以防止拖动?
不行不要怪我,不过鉴于时间的问题,我有一个大概的想法可以入手。 ;) 只需为签名创建一个 onClickListener
/ onTouchListener
。
如果客户点击或触摸它,Bottomsheet
的拖动功能将被禁用,上面提到的 Listener:
final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
不要忘记在不再点击或触摸签名后启用拖动功能。干杯。
@Lance:这个对我有用:订阅 setOnTouchListener 然后更改 isDraggable on touch up/down.
signatureCaptureControl.setOnTouchListener { v, event ->
when (event.action) {
MotionEvent.ACTION_UP -> {
bottomSheetBehavior.isDraggable = true
v.performClick()
}
MotionEvent.ACTION_DOWN -> bottomSheetBehavior.isDraggable = false
}
}
底部sheet UI默认是dragable.That的就好了,我要的是可以拖动的。但是在底部的某个特定部分sheet,我想禁用拖动。
我正在使用底部 sheet 向用户显示收据。然后用户必须在收据上签名。 UI 中有一个可以接受签名的视图。但由于底部 sheet 是可拖动的,因此签署收据会摇动 sheet 的位置。当用户的触摸位于签名控件内时,有什么方法可以防止拖动?
不行不要怪我,不过鉴于时间的问题,我有一个大概的想法可以入手。 ;) 只需为签名创建一个 onClickListener
/ onTouchListener
。
如果客户点击或触摸它,Bottomsheet
的拖动功能将被禁用,上面提到的 Listener:
final BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_DRAGGING) {
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
不要忘记在不再点击或触摸签名后启用拖动功能。干杯。
@Lance:这个对我有用:订阅 setOnTouchListener 然后更改 isDraggable on touch up/down.
signatureCaptureControl.setOnTouchListener { v, event ->
when (event.action) {
MotionEvent.ACTION_UP -> {
bottomSheetBehavior.isDraggable = true
v.performClick()
}
MotionEvent.ACTION_DOWN -> bottomSheetBehavior.isDraggable = false
}
}