當我按下按鈕的手指並將其移動到按鈕的界限外時,onTouchListener
繼續觸發。Android按鈕onTouchListener觸發外部界限
當我按下按鈕上的一個手指和按鈕外的另一個手指時,會發生同樣的事情:我的onTouchListener
會觸發第二根手指。
我該如何避免這種情況?只有當我按下按鈕的邊界時,我纔會觸發我的onTouchListener
。
這是我onTouchListener
實施
View.OnTouchListener onTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (fingerDown) {
xHistoricalFirstFinger = (int) event.getX();
yHistoricalFirstFinger = (int) event.getY();
xFirstClick = xHistoricalFirstFinger;
yFirstClick = yHistoricalFirstFinger;
//counter++;
fingerDown = false;
}
x = (int) event.getX();
y = (int) event.getY();
Log.v("Touched", client.remoteAdress.toString());
mouseMoveProvider.nextX = x - xHistoricalFirstFinger;
mouseMoveProvider.nextY = y - yHistoricalFirstFinger;
mouseMoveProvider.Ready = true;
xHistoricalFirstFinger = x;
yHistoricalFirstFinger = y;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (x - xFirstClick == 0 & y - yFirstClick == 0) {
new Thread(new Runnable() {
@Override
public void run() {
try {
client.MakeMove();
} catch (IOException e) {
e.printStackTrace();
NetworkListener.HandleNetworkIsUreachableException(context);
}
}
}).start();
}
fingerDown = true;
}
return true;
}
};
分享您的觸摸監聽器實現。任何不使用點擊監聽器的原因? – Shaishav
不,我只需要觸摸監聽器 – Kotelnikov