Android识别手势
我导入了手势示例并创建了自己的应用程序。布局中有一个按钮和gestureoverlayview。该按钮启动 GestureBuilderActivity.class,我可以在其中添加或删除手势(这是示例)。在按钮下,在 GestureOverlayView 中我可以绘制手势。布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to see gestures"
android:id="@+id/Button01"
/>
<android.gesture.GestureOverlayView
android:id="@+id/gestures"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" />
</LinearLayout>
从示例中我知道这是我找到手势的地方:
final String path = new File(Environment.getExternalStorageDirectory(),
"gestures").getAbsolutePath();
并且 toast 消息显示(仍在示例中)手势保存在 /mnt/sdcard/gestures 中:
Toast.makeText(this, getString(R.string.save_success, path), Toast.LENGTH_LONG).show();
如何使应用程序识别我的手势在吐司消息中绘制并显示它的名字?
I imported the gesture example and created my own app. There is a button and the gestureoverlayview in the layout. The button starts the GestureBuilderActivity.class, where I can add or remove gestures (this is the example). Under the button, in the GestureOverlayView I can draw gestures. Layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click to see gestures"
android:id="@+id/Button01"
/>
<android.gesture.GestureOverlayView
android:id="@+id/gestures"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1.0" />
</LinearLayout>
From the example I know that this is where I find the gestures:
final String path = new File(Environment.getExternalStorageDirectory(),
"gestures").getAbsolutePath();
and the toast msg shows (still in the example) that the gesture is saved in /mnt/sdcard/gestures:
Toast.makeText(this, getString(R.string.save_success, path), Toast.LENGTH_LONG).show();
How can I make the app recognize the gesture I draw and show me its name in a toast msg?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我会阅读这篇解释如何使用手势的短文。
要识别手势,您需要向 GestureOverlayView 提供 OnGesturePerformedListener。在此示例中,我只是让 Activity 实现 OnGesturePerformedListener。
First, I would read this short article that explains how to use gestures.
To recognize a gesture you need to provide an OnGesturePerformedListener to GestureOverlayView. In this example, I just had the Activity implement the OnGesturePerformedListener.