gpt4 book ai didi

Android 检测悬停在 GridView 中的按钮上

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:31:38 24 4
gpt4 key购买 nike

我有一个带有 6 个按钮的 GridView,我需要检测用户当前使用的是哪个按钮,当用户到达特定按钮的边缘时,他的手指会振动。是否可以在 GridView 中的按钮层以某种方式执行此操作,或者更好地在我的 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;
}

关于Android 检测悬停在 GridView 中的按钮上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8166866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com