【发布时间】:2011-12-31 07:10:24
【问题描述】:
我有带有 6 个按钮的 GridView,当用户到达特定按钮的边缘时,我需要检测用户当前用手指在哪个按钮上振动。 是否可以在 GridView 中的按钮层以某种方式做到这一点,或者更好地在我的 gridview 中实现它并计算每个按钮边缘的坐标?
【问题讨论】:
标签: android hover android-gridview
我有带有 6 个按钮的 GridView,当用户到达特定按钮的边缘时,我需要检测用户当前用手指在哪个按钮上振动。 是否可以在 GridView 中的按钮层以某种方式做到这一点,或者更好地在我的 gridview 中实现它并计算每个按钮边缘的坐标?
【问题讨论】:
标签: android hover android-gridview
您可以定义自己的 OnTouchListener 来捕获 GridView 中的 View 接收到的事件。像这样的:
View.OnTouchListener listener = new View.OnTouchListener {
public void onTouch ( View v, MotionEvent event ) {
/** Check the event and the View here */
return false; // Return false, so the system will behave as always
}
}
public View getView ( int position, View v, ViewGroup vg ) {
/** Create your View here */
v.setOnTouchListener ( listener );
/**
Maybe you could need this too
vg.setOnTouchListener ( listener );
*/
return v;
}
【讨论】: