5
我有6個按鈕的GridView,我需要檢測當用戶到達特定按鈕的邊緣時,用戶正在用他的手指用哪個按鈕進行振動。 是否有可能以某種方式在GridView中的按鈕層完成它,或者更好地在GridView中實現它並計算每個按鈕邊的座標?Android檢測懸停在GridView中的按鈕
我有6個按鈕的GridView,我需要檢測當用戶到達特定按鈕的邊緣時,用戶正在用他的手指用哪個按鈕進行振動。 是否有可能以某種方式在GridView中的按鈕層完成它,或者更好地在GridView中實現它並計算每個按鈕邊的座標?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;
}