我想让fling
手势检测在我的Android应用程序中工作。
我有一个包含9个ImageView
的GridLayout
。来源可以在这里找到:罗曼人的网格布局。
我拿的那个文件来自Romain Guy的光流应用,只是稍微修改了一下。
对于简单的点击情况,我只需要为我添加的每个ImageView
设置onClickListener
作为实现View.OnClickListener
的主activity
。实现识别fling
的东西似乎要复杂得多。我想这是因为它可能跨越views
?
如果我的活动实现了OnGestureListener
我不知道如何将其设置为手势侦听器Grid
或Image
的意见,我添加。
public class SelectFilterActivity extends Activity implementsView.OnClickListener, OnGestureListener { ...
If my activity implementsOnTouchListener
then I have noonFling
method to override
(it hastwo events as parameters allowing meto determine if the fling wasnoteworthy).
public class SelectFilterActivity extends Activity implementsView.OnClickListener, OnTouchListener { ...
If I make a custom View
, like GestureImageView
that extends ImageView
I don't know how to tell the activity that a fling
has occurred from the view. In any case, I tried this and the methods weren't called when I touched the screen.
I really just need a concrete example of this working across views. What, when and how should I attach this listener
? I need to be able to detect single clicks also.
// Gesture detectionmGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {int dx = (int) (e2.getX() - e1.getX());// don't accept the fling if it's too short// as it may conflict with a button pushif (Math.abs(dx) > MAJOR_MOVE && Math.abs(velocityX) > Math.absvelocityY)) {if (velocityX > 0) {moveRight();} else {moveLeft();}return true;} else {return false;}}});
是否有可能在屏幕顶部放置一个透明视图来捕获投掷?
如果我选择不从XML中inflate
我的子图像视图,我可以将GestureDetector
作为构造函数参数传递给我创建的ImageView
的新子类吗?
这是我试图让fling
检测工作的非常简单的活动:选择过滤器活动(从Photostream适配)。
我一直在看这些来源:
到目前为止,没有什么对我有用,我希望得到一些指示。