开始处理手势事件

发布于 2024-10-08 06:21:00 字数 190 浏览 11 评论 0原文

我是安卓新手。我刚刚浏览了我的幻灯片应用程序。

我想像 Facebook 应用程序一样使用触摸事件制作图像幻灯片。当我们单击图像并将其向左滑动时,会显示新图像;当我们向右滑动手指时,会显示最后一个旧图像。

我不知道这是如何运作的以及如何开始。在这种情况下,有人可以帮助我开始提供教程和提示吗?

我只是想要图像上的效果。

I have been new to android. I have just gone through my slideshow app.

I want to make image slide using touch event just like facebook app. when we click on image and swipe it to left then new image shown and when swipe finger towards right then last old image is shown.

I don't know how this works and how to start with it. Can any one help me in this case to start with like providing tutorials and tips ?

I just want effect on the image.

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

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

发布评论

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

评论(2

傲世九天 2024-10-15 06:21:00

处理简单的触摸事件的工作原理如下:

  1. 您的 Activity 中需要一个 OnTouchListener。通过实现 OnTouchListener 接口来添加它。
  2. 您必须重写 onTouch(View v, MotionEvent event) 方法。如果识别到触摸手势,则会调用此函数。
  3. 现在,您可以通过 MotionEvent 在 onTouch 方法中获取有关 Touch(在 Android 中称为 MotionEvent)的所有信息。查看 MotionEvent-Class 文档,使用正确的方法来处理您的事件滑动手势。
  4. 你可以首先询问到底发生了什么行动。调用 getAction()。它将返回操作的类型。最简单的方法是对 ACTION_MOVE 做出反应。
  5. 然后使用 getHistoricalX(int)/getHistoricalY(int) 和 getX(int) 和 getY(int) 询问触摸事件的起源和触摸的后续位置(注意:这些方法仅适用于 ACTION_MOVE 事件 - 在你的情况没问题)。
  6. 现在,当您有了滑动手势的开始和结束坐标后,您就可以计算滑动的长度(以像素为单位)和滑动的方向,这就是您所需要的。

祝你好运!

Handling simple touch events works the following:

  1. You need an OnTouchListener in your Activity. Add it by implementing the OnTouchListener interface.
  2. You will have to override the onTouch(View v, MotionEvent event) method. This will be called if a touch gesture is recognized.
  3. Now you get all the information about the Touch (in Android it is called MotionEvent) in the onTouch Method via the MotionEvent. Look at the MotionEvent-Class documentation to use the correct methods to handle your swipe gesture.
  4. You could first ask what action really happened. Call getAction(). It will return the type of action. The easiest way would be to react to ACTION_MOVE.
  5. Then ask for the origin of the touch event and the later position of the touch by using getHistoricalX(int)/getHistoricalY(int) and getX(int) and getY(int) (attention: these methods are only usable for ACTION_MOVE events - in your case it is ok).
  6. Now as you have the start and end coords of the swipe gesture, you can calculate the length of the swipe in pixels and the direction of the swipe and that is all what you need.

Good Luck!

一杯敬自由 2024-10-15 06:21:00

您可能需要两条信息。首先,你所说的就是画廊。有几个关于如何使用图库的很好的示例,基本思想是您获得一个 BaseAdapter 类,该类获取视图并将其附加到图库。请参阅本教程作为示例,或者只是谷歌Android Gallery示例,您会发现很多例子。

第二个是手势编程。看看本教程< /a> 了解更多信息

There's two bits of information that you might want. The first thing is, what you are referring to is called a gallery. There's several great examples of how to use a gallery, the basic idea is you get a BaseAdapter Class that gets the view and attach it to the gallery. See this tutorial for an example, or just google Android Gallery Example, you'll find alot of examples.

The second is gesture programming. Take a look at this tutorial for more information

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