Android swipe layout to dismiss

后端 未结 3 805
渐次进展
渐次进展 2021-01-13 13:43

I\'m trying to make a swipeable layout so you can swipe it to dismiss like in Google now. I managed to getting it worked on a view such as button using this codes:

S

相关标签:
3条回答
  • 2021-01-13 14:20

    you should know that if you return false for action_down , you will not get any further actions regarding this touch event

    https://developer.android.com/training/gestures/detector#capture-touch-events-for-an-activity-or-view

    "Beware of creating a listener that returns false for the ACTION_DOWN event. If you do this, the listener will not be called for the subsequent ACTION_MOVE and ACTION_UP string of events. This is because ACTION_DOWN is the starting point for all touch events."

    0 讨论(0)
  • 2021-01-13 14:21

    This code worked for me. I was able to Swipe-dismiss Relative and Linear Layouts. Just make sure you call the removeView() method from the correct immediate parent layout.

                @Override
                public void onDismiss(View view, Object token) {
                ViewGroup parent=(ViewGroup)dissmissableLayout.getParent();
                parent.removeView(dismissableLayout);
                }
    
    0 讨论(0)
  • 2021-01-13 14:38

    I just used the same SwipeDismissTouchListener class to implement a swipe gesture on a RelativeLayout, and at first had the problem of ACTION_MOVE never getting passed through, or any action other than ACTION_DOWN.

    Found out that the problem is in ACTION_DOWN returning false. So just change your case ACTION_DOWN to return true, and it will work properly, as that will make other actions also get passed through.

    0 讨论(0)
提交回复
热议问题