我試圖在觸摸列表視圖時獲取位置,以便在特定位置觸摸時顯示敬酒。如何在列表視圖中獲取觸摸位置?
這裏是我的觸動聽者的列表視圖: -
customListFilter.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent event) {
int actionX = (int) event.getX();
int actionY = (int) event.getY();
int extraTapArea = 13;
int x = (int) (actionX + extraTapArea);
int y = (int) (actionY - extraTapArea);
x = getWidth() - x;
if(x <= 0){
x += extraTapArea;
}
if (y <= 0)
y = actionY;
if ((actionX,actionY).contains(x, y)) {
// Show Toast Here
}
return false;
}
});
請幫我看看我的邏輯。 基本上,如果我碰在ListView右側或左側,但沒有中間環節,它應該顯示舉杯
如果您贊成原因,請做評論。 –