自定义ListView

import android.content.Context;

import android.util.AttributeSet;

import android.view.MotionEvent;

import android.widget.ListView;

public class LiveCustomListView extends ListView {

public LiveCustomListView(Context context) {

super(context);

}

public LiveCustomListView(Context context, AttributeSet attrs) {

super(context, attrs);

}

private float mLastX;

private float mLastY;

@Override

public boolean onInterceptTouchEvent(MotionEvent ev) {

//避免左右滑动水平图片时容易触发上下滑动列表

switch (ev.getAction()) {

case MotionEvent.ACTION_DOWN:

mLastX = ev.getX();

mLastY = ev.getY();

break;

case MotionEvent.ACTION_MOVE:

if (Math.abs(mLastX - ev.getX()) > Math.abs(mLastY - ev.getY())) {

return false;

}

break;

case MotionEvent.ACTION_UP:

case MotionEvent.ACTION_CANCEL:

break;

}

return super.onInterceptTouchEvent(ev);

}

}

原文:http://www.cnblogs.com/agilezhu/p/5881171.html

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐