【问题标题】:Android detect hover on Buttons in GridViewAndroid检测悬停在GridView中的按钮上
【发布时间】:2011-12-31 07:10:24
【问题描述】:

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

【问题讨论】:

    标签: android hover android-gridview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2017-12-14
      • 1970-01-01
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 2018-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多