Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewDragHelper: how to use it?

In the Google IO 2013, Google has announced a new version of the Support Library, which includes ViewDragHelper class. I saw the docs, but I couldn't find any sample of usage for this class.

For example, a very typical situation: I have a custom view, which extends from FrameLayout and allows to drag some of the Views inside. For example, let it be a Button. I override onTouchEvent() and onInterceptTouchEvent() within my custom view, and if the button of the rect contains the touch coordinates and this is not a simple click, then I start to drag.

So, what I must do with ViewDragHelper to get that? The clicks to the Button should process correctly.

like image 522
bvitaliyg Avatar asked Jul 21 '13 12:07

bvitaliyg


2 Answers

Here is a good example shows how ViewDragHelper is used. https://github.com/umano/AndroidSlidingUpPanel

Use ViewDragHelper.create() method to create it. Use the shouldInterceptTouchEvent() to determine if you should intercept the touch event from child views.

Use smootSlideViewTo() method to move the child view within your customized view.

like image 78
niyanshi Avatar answered Oct 18 '22 03:10

niyanshi


Here is a nice post about how to use ViewDragHelper

  • each-navigation-drawer-hides-a-viewdraghelper
like image 18
shaobin0604 Avatar answered Oct 18 '22 04:10

shaobin0604