Android的MotionEvent当手指进入或离开视图 [英] android MotionEvent when finger enter or leaves view

查看:584
本文介绍了Android的MotionEvent当手指进入或离开视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我wan't开发名为巴尔达的游戏。

I wan't to develop game named "Balda".

我有imageviews的二维网格(或按钮,也许)。
用户应该能够移动他的手指上的网格,应用程序应该知道至极图像栅格被感动了这个move.So,在下面的图片就是我想要的目的。 A - 是启动地步用户$ P $在屏幕上pssed。 B是终点在哪里手指离开屏幕。我需要知道被感动什么的图像(有蓝色的图片)。

I have a 2d grid of imageviews (or buttons, maybe). User should be able move his finger on the grid, and app should know wich images in grid was touched in this move.So, in the picture below is what I'm trying to achieve. A - is start point where user pressed on screen. B is end point where finger leaves the screen. And I need to know what images were touched (There are blue in the picture).

我知道我可以做这样的事情这个。但我认为这是一个错误的解决方案,因为它违背由responsibilitys赋予功能的原则。
我认为这是ImageView的知道什么时候手指进入其边界,当它离开其边界的责任。
我想,这将是Android的API。它有MotionEvent像EVENT_HOVER_ENTER和EVENT_HOVER_LEAVE,但它不是用手指工作。手指pressed一些查看后,将收到的所有其他MotionEvents,如果我得到它的权利。

I know that I can do something like this. But I think that this is a wrong solution, because It contradicts the principle of giving functionality by responsibilitys. I think that it is responsibility of the imageView to know when finger enters its borders and when it is leaving its borders. I thought, that this would be in android API. And it has MotionEvent like EVENT_HOVER_ENTER and EVENT_HOVER_LEAVE but it's not working with finger. After finger is pressed on some View it will recieve all other MotionEvents, if I get it right.

我认为这是错误的。我能做些什么来得到这个功能呢?也许我可以创建一些自定义的监听器和自定义视图,支持他们呢?

I think that this is wrong. What can I do to get this functionality? Maybe I could create some custom listeners and custom Views, that supports them?

推荐答案

我觉得你的要求是稍微类似于定制GridView的。

I think your requirement is slightly similar to custom gridview.

您可以试试下面的步骤 -

You can try below steps-

1)创建自定义视图

2)安装TouchListener它。

2)Attach TouchListener to it.

3)划分这一观点为4×3的矩阵。

3)Divide this view into 4*3 matrix.

4)你的映射图像,这4 * 3的矩阵

4)Map your images to this 4*3 matrix

5)写一个函数这使细胞数量分别toTouched坐标

5)Write a function which gives the cell number respective toTouched Co-ordinates

6)获得细胞数量后,获得该手机号码映射图像

6)After getting cell number;get the mapped image for that cell number

7)将这个图像中的ArrayList

7)Put this image in arraylist

8)当用户拿起他的手指,你会得到感动的图像(做任何你想用它)。

8)When user lifts his finger you will get arraylist of touched images(do whatever you want with it).

9)请记住把这个自定义视图在活动

9)Remember to put this custom view in your activity

告诉我,如果你有什么疑问或担忧

Tell me,if you have any doubt or concern

这篇关于Android的MotionEvent当手指进入或离开视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆