我有這樣的項目的網格:觸摸動畫和OnItemClick在適配器視圖
http://petromi.com/get/ba4a24f852.png
而且我想,當用戶觸摸它來播放動畫專輯封面。我創建了一個類用於此目的:
class TouchAnimationHelper {
...
public void setItemTouchAnimation(final View view) {
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
Log.d("Touch action: [%s]", action);
if (action == MotionEvent.ACTION_DOWN) {
view.startAnimation(sDecAnimation);
return true;
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
if (action == MotionEvent.ACTION_UP) {
sIncAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
sIncAnimation.setAnimationListener(null);
view.performClick();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
view.startAnimation(sIncAnimation);
return true;
}
return false;
}
});
}
}
在適配器的getView
方法我稱之爲:
mTouchAnimationHelper.setItemTouchAnimation(view.findViewById(R.id.album_cover));
但結果並不完全我想要的。 觸摸時動畫正在工作。但沒有調用Grid的onItemClick
。只有在點擊圖像下方的文字時纔會調用它。我怎樣才能打電話?
我已經嘗試了一些解決方案,但他們並沒有全成:
始終在
onTouch
返回false。但在這種情況下,沒有其他觸摸動作繼續進行,動畫不會播放。其他參數傳遞到
setItemTouchAnimation
和調用adapterView.performItemClick(view, position, id)
代替view.performClick()
。但在這種情況下,我得到了奇怪的混亂:提出 事件的項目ID不匹配點擊的項目ID。我對 不瞭解,爲什麼如此。
還有其他想法嗎?
你檢查http://developer.android.com/reference/android/view /ViewGroup.html#requestDisallowInterceptTouchEvent%28boolean%29 – Naveen
謝謝。我試過這樣的東西:http://stackoverflow.com/questions/14537513/how-do-i-scroll-a-listview-after-requestdisallowintercepttouchevent-in-ontouchli。但我無法工作 – darja