android - 在安卓中创建手势

标签 android android-layout android-widget

您好,我正在学习本教程

http://www.vogella.de/articles/AndroidGestures/article.html 我想创建一个应用程序,用户可以在其中添加他的手势到我的应用程序中,然后使用它进行身份验证。我知道使用这段代码我可以检查他输入的手势是否正确。

package de.vogella.android.gestures;

导入java.util.ArrayList;

public class GestureTest extends Activity implements OnGesturePerformedListener {
    private GestureLibrary gestureLib;


/** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        GestureOverlayView gestureOverlayView = new GestureOverlayView(this);
        View inflate = getLayoutInflater().inflate(R.layout.main, null);
        gestureOverlayView.addView(inflate);
        gestureOverlayView.addOnGesturePerformedListener(this);
        gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
        if (!gestureLib.load()) {
            finish();
        }
        setContentView(gestureOverlayView);
    }

    @Override
    public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
        ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
        for (Prediction prediction : predictions) {
            if (prediction.score > 1.0) {
                Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }
}

好的,但请帮助我了解如何在 R.raw.animate 文件中添加手势。请建议在 Android 应用程序中添加手势的任何方式或链接。

最佳答案

摘自here :

Android 1.6 and higher SDK platforms include a new application pre-installed on the emulator, called Gestures Builder. You can use this application to create a set of pre-defined gestures for your own application...

...

As you can see, a gesture is always associated with a name. That name is very important because it identifies each gesture within your application. The names do not have to be unique. Actually it can be very useful to have several gestures with the same name to increase the precision of the recognition. Every time you add or edit a gesture in the Gestures Builder, a file is generated on the emulator's SD card, /sdcard/gestures. This file contains the description of all the gestures, and you will need to package it inside your application inside the resources directory, in /res/raw.

Here你有 Gesture Builder 的源代码

手势生成器安装在模拟器中,但您可以从here 下载它。

及手势源码实例here

关于android - 在安卓中创建手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7778334/

相关文章:

android - Android Actionbar (Marquee) 中的可自动滚动标题

android - 禁用与收件人发送电子邮件 Intent 的直接共享

java - 获取 io.realm.exceptions.RealmException : Could not find the generated ValidationList class when trying to get a Realm object

android - 我在 Here Maps 中不断收到 SSL 错误

android - 如何获取 View /布局的 z-index ?或者如何知道它是否在前面?

android - ImageView 未出现在小部件中

java - 如何通过检查数组值将数组拆分为不同数组或具有不同键的同一数组

Android:如何在 Activity (不是 fragment )之间滑动,主/细节最佳设置

android - 使用 RelativeLayout 重叠 ViewPager 选项卡

java - 防止小部件在短时间内被多次点击