I want to get fling
gesture detection working in my Android application.
(我想fling
手势检测工作在我的Android应用程序。)
What I have is a GridLayout
that contains 9 ImageView
s.
(我所拥有的是一个GridLayout
,其中包含9个ImageView
。)
(可以在这里找到源: Romain Guys的Grid Layout 。)
That file I take is from Romain Guy's Photostream application and has only been slightly adapted.
(我带的那个文件来自Romain Guy的Photostream应用程序 ,只是稍作修改。)
For the simple click situation I need only set the onClickListener
for each ImageView
I add to be the main activity
which implements View.OnClickListener
.
(对于简单的点击情况我只需要设置onClickListener
每个ImageView
我添加是主要的activity
,它实现View.OnClickListener
。)
fling
. (实现识别出fling
东西似乎无限复杂。)
views
? (我认为这是因为它可能跨越views
?)
If my activity implements
OnGestureListener
I don't know how to set that as the gesture listener for theGrid
or theImage
views that I add.(如果我的活动实现了
OnGestureListener
我将不知道如何将其设置为我添加的Grid
或Image
视图的手势侦听器。)public class SelectFilterActivity extends Activity implements View.OnClickListener, OnGestureListener { ...
If my activity implements
OnTouchListener
then I have noonFling
method tooverride
(it has two events as parameters allowing me to determine if the fling was noteworthy).(如果我的活动实现了
OnTouchListener
那么我就没有要override
onFling
方法(它有两个事件作为参数,使我可以确定onFling
是否值得关注)。)public class SelectFilterActivity extends Activity implements View.OnClickListener, OnTouchListener { ...
If I make a custom
View
, likeGestureImageView
that extendsImageView
I don't know how to tell the activity that afling
has occurred from the view.(如果我做一个自定义的
In any case, I tried this and the methods weren't called when I touched the screen.View
,如GestureImageView
扩展ImageView
,我不知道怎么跟一个活动fling
已经从视图中发生。)(无论如何,我都尝试过这种方法,并且触摸屏幕时不会调用这些方法。)
I really just need a concrete example of this working across views.
(我真的只需要一个跨视图工作的具体示例。)
What, when and how should I attach thislistener
? (什么,何时以及如何附加此listener
?)
(我还需要能够检测到单击。)
// Gesture detection
mGestureDetector = 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 push
if (Math.abs(dx) > MAJOR_MOVE && Math.abs(velocityX) > Math.absvelocityY)) {
if (velocityX > 0) {
moveRight();
} else {
moveLeft();
}
return true;
} else {
return false;
}
}
});
Is it possible to lay a transparent view over the top of my screen to capture flings?
(是否可以在屏幕上方放置透明视图以捕获抓拍?)
If I choose not to inflate
my child image views from XML can I pass the GestureDetector
as a constructor parameter to a new subclass of ImageView
that I create?
(如果我选择不inflate
从XML我的孩子形象的意见我可以传递GestureDetector
作为构造函数参数的一个新的子类ImageView
,我创造?)
This is the very simple activity that I'm trying to get the fling
detection to work for: SelectFilterActivity (Adapted from photostream) .
(这是一个非常简单的活动,我正在尝试使fling
检测起作用: SelectFilterActivity(从photostream改编而成) 。)
I've been looking at these sources:
(我一直在寻找这些来源:)
Nothing has worked for me so far and I was hoping for some pointers.
(到目前为止,对我来说什么都没有奏效,我一直希望有一些指点。)
ask by gav translate from so