ViewDragHelper: how to use it?
Asked Answered
N

2

20

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.

Nettles answered 21/7, 2013 at 12:51 Comment(3)
You can try to check this project on Git Hub : github.com/umano/AndroidSlidingUpPanel Actually I am trying to find out how it works right now. Currently I stacked on on a moment where I can't find any ViewDragHelper in my support library jar. :)Unparliamentary
This class would be in only last version of Support Library, dated May 2013. Try to update your Support Library via SDKManager. Look in android.v4.support.widget package.Nettles
Have you managed to get a Button that handles both clicks and drags ?Inversion
A
17

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.

Atypical answered 30/7, 2013 at 15:21 Comment(1)
smootSlideViewTo is not working for me. Als o i cannot find any examples hw to use it (except SlidingUpPanel)Enceinte
B
19

Here is a nice post about how to use ViewDragHelper

Bethought answered 8/4, 2014 at 2:52 Comment(4)
link is broken.Roodepoortmaraisburg
old.flavienlaurent.com/blog/2013/08/28/…Displace
@Bethought I found your article very enlightening, and have almost modified the YoutubeLayout class so I can use it with my own content (2 linear layouts, with very diverse content). However, I find a bit difficult to make some tweaks to the class, although I believe is related with my short knowledge of the ViewDragHelper. Do you think is it possible to make the content not to fully take the height of the screen? I'd like it to stick with my defined android:layout_height="wrap_content" , and at the moment, it's ignoring it.Radarman
nice tutorial really helpfulCoyle
A
17

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.

Atypical answered 30/7, 2013 at 15:21 Comment(1)
smootSlideViewTo is not working for me. Als o i cannot find any examples hw to use it (except SlidingUpPanel)Enceinte

© 2022 - 2024 — McMap. All rights reserved.