抽屉布局在向其添加动画后未检测到内部滑动事件

Drawer-Layout not detecting swipe event inside after adding animation to it

Assalamualikum 大家: 我正在制作一个评论面板,就像 Google plus app 所做的那样。我在该抽屉布局中使用抽屉布局和下拉刷新库 ( https://github.com/naver/android-pull-to-refresh ) 来显示评论。然后我在该列表视图上添加了另一个功能,即:当我向其他方向滑动时,删除按钮出现并带有动画以删除任何评论。 我的问题是,当我滑动打开任何行上的删除按钮时,抽屉布局不会关闭,除非我特别滑动列表视图项目。如果我在列表视图的项目下方滑动,它不会关闭抽屉布局。我在列表视图上添加了触摸事件并将其高度设置为填充父级以解决此问题,但触摸事件仅在不低于列表视图的列表视图项目上检测到。 所以我无法关闭列表视图下方的删除按钮。

下面的代码片段是我的评论活页夹的代码class:

 // To animate view slide out from top to bottom
    public void slideToRight(View view, boolean firstTime) {

        TranslateAnimation animate = new TranslateAnimation(-deleteButton.getWidth(), 0, 0, 0);
        animate.setDuration((firstTime) ? 0 : 500);
        animate.setFillAfter(true);
        if (!firstTime) {
            view.startAnimation(animate);
        }
        animate = new TranslateAnimation(0, deleteButton.getWidth() * 2, 0, 0);
        animate.setDuration((firstTime) ? 0 : 500);
        animate.setFillAfter(true);
        deleteButton.startAnimation(animate);


        // deleteButton.setVisibility(GONE);
     //   Log.d(LOG_TAG, "test:" + "Swipe Left to Right");
    }

    // To animate view slide out from bottom to top
    public void slideToLeft(View view, boolean firstTime) {
        TranslateAnimation animate = new TranslateAnimation(0, -deleteButton.getWidth(), 0, 0);
        animate.setDuration((firstTime) ? 0 : 500);
        animate.setFillAfter(true);
        view.startAnimation(animate);
        animate = new TranslateAnimation(deleteButton.getWidth(), 0, 0, 0);
        animate.setDuration((firstTime) ? 0 : 500);
        animate.setFillAfter(true);
//        deleteButton.setVisibility(VISIBLE);
        deleteButton.startAnimation(animate);
       // Log.d(LOG_TAG, "test:" + "Swipe Right to Left");
    }

    public void changeDeltebuttonUIVisibilty(boolean status) {
        if (((getFirstCommentUser() != null) && (getThisUser() != null) && (getFirstCommentUser().getUserId().equals(getThisUser().getUserId())))||(ConvoMain.deleteCounter1>0||deleteCounter>0)) {


            if (commentDeleteListener != null) {



                if (status && ((ConvoMain.deleteCounter1 == 0)&&(deleteCounter==0))&&deleteButton.getVisibility() != VISIBLE) {
                    commentUserNameTimetxt.setMovementMethod(null);
                    conversation.isSelectedForDelete=true;
                    CommentItemBinder.selectedForDeleteConversation=conversation;
                    commentItemInnerContainer.startAnimation(fadeIn);
//                    commentUserNameTimetxt.setMovementMethod(null);

                    deleteButton.setVisibility(VISIBLE);
                    slideToLeft(commentInnerContainer, false);
                    //
                 //   Log.d(LOG_TAG, "Conversation deletion selected: " + conversation.conversationID);



                    test++;
                    //slideToLeft(deleteButton);

                            ConvoMain.context.lockCommentDrawer();

                    deleteCounter++;
                    ConvoMain.deleteCounter1++;
                    deleteButton.setOnClickListener(deleteButtonListener);

                } else if (deleteButton.getVisibility() == VISIBLE && ((ConvoMain.deleteCounter1 > 0)||(deleteCounter > 0))) {
                    commentUserNameTimetxt.setMovementMethod(linkMovementMethod1);

                    commentItemInnerContainer.startAnimation(fadeOut);


                    slideToRight(commentInnerContainer, false);

                    deleteButton.setOnClickListener(null);

                    deleteCounter = 0;
                    ConvoMain.deleteCounter1 = 0;
                    deleteButton.setVisibility(GONE);

                    conversation.isSelectedForDelete = false;
                    CommentItemBinder.selectedForDeleteConversation=null;
                    new Handler().postDelayed(new Runnable() {
                        public void run() {
                            ConvoMain.context.unlockCommentDrawer();
                            deleteButton.clearAnimation();
                            commentInnerContainer.clearAnimation();
                        }
                    }, 500);


                    // commentUserNameTimetxt.setMovementMethod(linkMovementMethod1);
                } else if((deleteButton.getVisibility() != VISIBLE)&& (ConvoMain.deleteCounter1>0)){


                    commentDeleteListener.onSwipeLeft("reset");

//                    commentItemInnerContainer.startAnimation(fadeOut);
//                    commentUserNameTimetxt.setMovementMethod(linkMovementMethod1);
//
//                    LinearLayout.LayoutParams params2 = (LinearLayout.LayoutParams) deleteButton.getLayoutParams();
//                    deleteButton.setVisibility(GONE);
                    //conversation.isSelectedForDelete = false;

                    ConvoMain.context.unlockCommentDrawer();
                }

            }
        } else {
            deleteButton.setVisibility(GONE);
            //conversation.isSelectedForDelete = false;
        }
    }

    OnClickListener deleteButtonListener = new OnClickListener() {
        @Override
        public void onClick(View view) {

            changeDeltebuttonUIVisibilty(false);
//           commentContenttxt.setEnabled(true);
//           commentUserNameTimetxt.setEnabled(true);
           // commentUserNameTimetxt.setMovementMethod(linkMovementMethod1);
            commentInnerContainer.startAnimation(fadeOut);

            commentDeleteListener.onSwipeLeft(conversation.conversationID);
            new Handler().postDelayed(new Runnable() {
                public void run() {
                    ConvoMain.context.unlockCommentDrawer();
                }
            }, 400);

        }
    };


    OnTouchListener onThumbTouch = new OnSwipeTouchListener(getContext()) {


        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                    deleteLock = false;
                    deleteUnLock = false;
                    downX = event.getX();
                    downY = event.getY();
                   // android.util.Log.d(LOG_TAG, "Action Down");
                    // mSwipeDetected = Action.None;
                    //   ConvoMain.context.lockCommentDrawe//);
//                return false; // allow other events like Click to be processed
                }

                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_MOVE: {
                    upX = event.getX();
                    upY = event.getY();
//                    android.util.Log.d(LOG_TAG, "Action Move");
                    float deltaX = downX - upX;
                    float deltaY = downY - upY;
//                    android.util.Log.d(LOG_TAG, "Action Move:"+deltaX+":"+deltaY);
                    // horizontal swipe detection

                    if ((deltaX > 0)) {

                        if (!deleteLock)
                            if ((Math.abs(deltaX)) > (HORIZONTAL_MIN_DISTANCE)) {
                               // android.util.Log.d(LOG_TAG, "Swipe Right to Left");
                                if ((deleteCounter == 0) && (ConvoMain.deleteCounter1 == 0)) {

                                    changeDeltebuttonUIVisibilty(true);
                                    //ConvoMain.context.lockCommentDrawer();
                                    deleteUnLock = true;
                                    //counter = 0;
                                    return false;
                                }

                                //return true;

                            }


                    }
                    if (deltaX <= 0) {
                        if (!deleteUnLock) {
                            if (deleteCounter > 0 || ConvoMain.deleteCounter1 > 0) {

                                if ((Math.abs(deltaX)) < (HORIZONTAL_MIN_DISTANCE)) {
                                  //  android.util.Log.d(LOG_TAG, "Swipe Left to Right");
//                            if ((deleteCounter == 0)&&(ConvoMain.deleteCounter1==0)) {

                                    changeDeltebuttonUIVisibilty(false);

                                    deleteLock = true;
                                    return false;
                                    //counter = 0;
//                            }
                                    //return true;

                                }
                            }else{

                            }
                        }


                    }
                    //return true;
                }
            }
            //MotionEvent.ACTION_DOWN

            return false;
        }
    };


    public void setCommentDeleteListener(commentDeleteListener commentDeleteListener) {
        // changeDeltebuttonUIVisibilty(false);
        this.commentDeleteListener = commentDeleteListener;
    }

    private commentDeleteListener commentDeleteListener;

    public static interface commentDeleteListener {
        public void onSwipeLeft(String test);

    }

伙计们,我找到了我自己问题的答案:那是当我打开抽屉时锁定它,这导致检测滑动事件的问题。但是现在我已经解锁了它,它解决了我的问题...:)

先解锁再尝试关闭