将ACTION_UP onTouchListener滚动到子窗口后不再调用GridView

时间:2015-01-08 23:32:50

标签: android

// getView()方法中GridView的子视图。 似乎需要实现自定义GridView,它将处理整个滚动和其他孩子的触摸操作。谢谢你的帮助。

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 个答案:

答案 0 :(得分:1)

这是因为滚动时,触摸事件会重新路由到网格视图。当发生这种情况时,您会看到ACTION_CANCEL。你需要考虑到这一点。