在 Android 应用程序中实现手势识别

发布于 2024-09-12 03:56:17 字数 449 浏览 8 评论 0原文

我正在向我的应用程序添加手势识别。我已经添加了 Android 开发人员手势文章中描述的视图,但是当涉及到添加时:

mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if(!mLibrary.load()){
   finish();
}

我应该将其放在代码中的什么位置,我是否必须为它创建一个新类,或者我可以将它放在内部类中,或者根本不需要上课?!我有一个类似于月球着陆器的设置,它由两个文件组成,其中一个是一个处理游戏的几乎所有物理和绘图的线程。另一个文件开始线程和 saveInstanceState 方法。

另外,mLibrary是什么类型?!我到处都找不到!!

我想我会将 OnGesturePerformed 方法放在我的线程中,因为这是我处理所有 keyUp 和 Down 事件的地方。

I am adding gesture recognition to my app. I have added the view as described in the Android Developers Gestures article but when it comes to adding:

mLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if(!mLibrary.load()){
   finish();
}

where do I put this in my code, do I have to create a new class for it, or can I have it in an inner class, or does it not need a class at all?! I have a set up similar to Lunar Lander which comprises of two files, one of which is a thread that handles pretty much all the physics and drawing of the game. The other file begins the thread and saveInstanceState method.

Furthermore, what type is mLibrary?! I cannot find out anywhere!!

I imagine I will put the OnGesturePerformed method in my thread as this is where I handle all keyUp and Down events.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉殇 2024-09-19 03:56:17

阅读这篇文章:http://developer.android.com/design/patterns/gestures。 html

在那段代码之后,您可以看到您必须实现一个侦听器。

public class GesturesActivity extends Activity implements OnGesturePerformedListener {
public void onCreate(Bundle savedInstanceState) {
    ..
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    //do the stuff you want ;)
}

如需完整示例,请下载此。
http ://code.google.com/p/apps-for-android/downloads/detail?name=GesturesDemos.zip&can=2&q=#makechanges

Read this article: http://developer.android.com/design/patterns/gestures.html.

After that piece of code you can see that you have to implement a listener.

public class GesturesActivity extends Activity implements OnGesturePerformedListener {
public void onCreate(Bundle savedInstanceState) {
    ..
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
    //do the stuff you want ;)
}

For a complete example download this.
http://code.google.com/p/apps-for-android/downloads/detail?name=GesturesDemos.zip&can=2&q=#makechanges

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文