ViewDragHelper: how to use it?
Solution 1
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.
Solution 2
Here is a nice post about how to use ViewDragHelper
Related videos on Youtube
Comments
-
bvitaliyg almost 4 years
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 theView
s inside. For example, let it be aButton
. I overrideonTouchEvent()
andonInterceptTouchEvent()
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 theButton
should process correctly.-
SSemashko almost 11 yearsYou 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. :)
-
bvitaliyg almost 11 yearsThis 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. -
Sébastien about 10 yearsHave you managed to get a Button that handles both clicks and drags ?
-
-
Vetalll over 10 yearssmootSlideViewTo is not working for me. Als o i cannot find any examples hw to use it (except SlidingUpPanel)
-
Mani almost 7 yearslink is broken.
-
Sachin Rao about 6 years
-
xarlymg89 almost 6 years@shaobin0604 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 theViewDragHelper
. 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 definedandroid:layout_height="wrap_content"
, and at the moment, it's ignoring it. -
Mightian over 5 yearsnice tutorial really helpful