Android 检测 GridView 中按钮上的悬停

发布于 2024-12-16 01:33:46 字数 131 浏览 1 评论 0原文

我有带有 6 个按钮的 GridView,我需要检测用户当前所在的按钮,当用户到达特定按钮的边缘时,手指会振动。 是否可以在 GridView 中的按钮层以某种方式执行此操作,或者更好地在我的 gridview 中实现它并计算每个按钮边缘的坐标?

I have GridView with 6 buttons and I need to detect which button is the user currently on with his finger to vibrate when user reach edge of the particular button.
Is it possible to do it somehow at the layer of the buttons in GridView, or is better implement it in my gridview and count coordinates of each button edges?

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

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

发布评论

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

评论(1

虐人心 2024-12-23 01:33:46

你可以定义自己的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;
}

You can define your own OnTouchListener to capture the events received by the View in the GridView. Something like this:

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