在项目中遇到一个需求,listview有一个比较复杂的item,item中有整体响应区事件,也有其他view的点击响应,listview的父亲要求滑动,在点击listview区域时要求在滑动的只是只滑动listview,但一般做法无法满足要求,listview无法兼顾点击事件与滑动。
解决的办法是,给item设置一个rootview,重写rootview的onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
final int action = event.getAction();
if(action == MotionEvent.ACTION_MOVE) {
if(null != scrollView) {
customListView.setEventFlag(true);
return false;
}
}