package com.gh.common.view;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;

/**
 * 重写RecyclerView 解决触摸事件
 * 
 * @author 黄壮华
 * 
 */
public class MyRecyclerView extends RecyclerView {

	public static boolean isCanMove = false;

	public MyRecyclerView(Context context, AttributeSet attrs) {
		super(context, attrs);
		
	}

	private float xDis;

	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		
		switch (ev.getAction()) {
		case MotionEvent.ACTION_DOWN:
			xDis = ev.getX();
			break;
		case MotionEvent.ACTION_MOVE:
			if (isCanMove) {
				if (xDis - ev.getX() > 0) {
					MyViewPager.isCanMove = true;
					return false;
				} else if (xDis - ev.getX() < 0) {
					isCanMove = false;
				}
			}
			xDis = ev.getX();
			break;
		default:
			break;
		}
		return super.dispatchTouchEvent(ev);
	}
}
