ViewDragHelper: how to use it?

23,853

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

Share:
23,853

Related videos on Youtube

bvitaliyg
Author by

bvitaliyg

Junior developer on PHP, Java, Ruby. Love nice code.

Updated on August 30, 2020

Comments

  • bvitaliyg
    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 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.

    • SSemashko
      SSemashko almost 11 years
      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. :)
    • bvitaliyg
      bvitaliyg almost 11 years
      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.
    • Sébastien
      Sébastien about 10 years
      Have you managed to get a Button that handles both clicks and drags ?
  • Vetalll
    Vetalll over 10 years
    smootSlideViewTo is not working for me. Als o i cannot find any examples hw to use it (except SlidingUpPanel)
  • Mani
    Mani almost 7 years
    link is broken.
  • Sachin Rao
    Sachin Rao about 6 years
  • xarlymg89
    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 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.
  • Mightian
    Mightian over 5 years
    nice tutorial really helpful