Android - ImageView onTouchListener没有响应触摸

时间:2016-12-16 22:29:27

标签: java android ontouchlistener touch-event bottom-sheet

情况我有一个BottomSheet,在右上角有一个按钮(ImageView)手动关闭它,当我点击该按钮时应用程序崩溃(下面是代码和logcat的)

PS:我正在使用片段

JAVA代码

bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            // React to state change
            if (newState == BottomSheetBehavior.STATE_EXPANDED){
                    CloseSheet.setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            if(event.getAction() == MotionEvent.ACTION_DOWN){
                            }
                            else if(event.getAction() == MotionEvent.ACTION_UP){
                                  //This is wher the error happens
                                bottomSheetBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);                                    
                            }
                            else if(event.getAction() == MotionEvent.ACTION_CANCEL){
                            }
                            return true;
                        }
                    });
            }else if (newState == BottomSheetBehavior.STATE_DRAGGING){
               bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); 
            }
        }

logcat的

FATAL EXCEPTION: main
Process: com.incorp.labs.appdict, PID: 26159
java.lang.IllegalArgumentException: Illegal state argument: 5
   at android.support.design.widget.BottomSheetBehavior.startSettlingAnimation(BottomSheetBehavior.java:624)
   at android.support.design.widget.BottomSheetBehavior.setState(BottomSheetBehavior.java:548)

0 个答案:

没有答案