问题描述
在谷歌IO 2013年,谷歌已经宣布支持库,其中包括 ViewDragHelper
类的新版本。我看到了文档,但我找不到的使用同类的样本。
On the Google IO 2013, Google has announced new version of Support Library, which includes ViewDragHelper
class.I saw the docs, but I couldn't find any sample of usage this class.
例如,很典型的情况:我有自定义视图,它扩展的FrameLayout,并允许拖动一些查看
里面。对于〔实施例,让我们这将是按钮。我重写的onTouchEvent()
和 onInterceptTouchEvent()
在我的自定义视图,如果矩形的按钮包含触摸坐标这不是简单的点击,我开始拖。
For example, very typical situation: I have custom view, which extends FrameLayout and allows drag some of the View
inside. For exmaple, let's it would be Button. I override onTouchEvent()
and onInterceptTouchEvent()
within my custom view, and if button of the rect contains touch coordinates and this is not simple click, I start drag.
所以,我必须做的 ViewDragHelper
来获取?在点击该按钮应正确处理。
So, what I must to do with ViewDragHelper
to get that? The clicks to the Button should process correctly.
推荐答案
下面是一个很好的例子,说明如何ViewDragHelper使用。https://github.com/umano/AndroidSlidingUpPanel
Here is a good example shows how ViewDragHelper is used.https://github.com/umano/AndroidSlidingUpPanel
使用ViewDragHelper.create()方法来创建它。使用shouldInterceptTouchEvent以确定是否应该从孩子的意见拦截触摸事件。使用smootSlideViewTo方法在自定义视图中移动子视图。
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.
这篇关于ViewDragHelper:如何使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!