2015-01-08 26 views
0

// getView()方法中GridView的子視圖。 似乎需要實現自定義GridView,它將處理他的孩子的整個滾動和其他觸摸操作。謝謝你的幫助。GridView在將ACTION_UP onTouchListener滾動到子項後不會調用

class ViewHolder implements View.OnTouchListener { 
    ImageView image; 
    TextView text; 
    int position; 
    RelativeLayout root; 

    public ViewHolder(View v, int position) { 
     this.image = (ImageView) v.findViewById(R.id.grid_image); 
     this.text = (TextView) v.findViewById(R.id.item_text); 
     this.root = (RelativeLayout) v.findViewById(R.id.root_layout); 
     this.position = position; 
     image.setOnTouchListener(this); 

    } 


    @Override 
    public boolean onTouch(View v, MotionEvent event) { 

     switch (event.getActionMasked()) { 
      case MotionEvent.ACTION_DOWN: 
       Log.e("DOWN", "YES"); 
       return true; 
      case MotionEvent.ACTION_MOVE: 

       break; 
      case MotionEvent.ACTION_UP: 
       Log.e("UP", "YES"); 
       break; 
     } 
     return true; 
    } 


} 

回答

1

這是因爲當您滾動時,觸摸事件被重新路由到網格視圖。發生這種情況時,您會看到ACTION_CANCEL。你需要解釋這一點。

+0

是的,我試圖使用ACTION_CANCEL,但它每次調用GridView滾動。即使在滾動時我也需要保存觸摸,如果手指向上移動,請調用ACTION_UP。 ACTION_CANCEL在任何情況下都會在完成觸摸事件(滾動時)時調用。我知道ScrollView攔截了他的孩子的觸摸(Grid內部的視圖),並沒有將完成的動作返回給孩子。 –

+0

然後,我認爲你需要編輯你的問題,併成爲一個很清楚你的需要。 Y我們最初的問題看起來像你不知道取消。你真正想要的是更深入的,我不確定它到底是什麼。 –

相關問題