自定义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);
}
}

相关文章:

  • 2022-01-05
  • 2022-12-23
  • 2021-10-20
  • 2021-11-17
  • 2021-09-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-20
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案