2014.04.22 ——— android listview header和左右滑动冲突
有的时候,listview的好hearder会展示焦点图,这些图是可以左右滑动的,但是可能整个listview也可以左右切换到其他fragment里面,这个时候就会有冲突了,解决:
public class HotListView extends ListView { private boolean mHeaderViewsScrollable = true; public HotListView(Context context) { super(context); } public HotListView(Context context, AttributeSet attrs) { super(context, attrs); } public HotListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public void setHeaderViewsScrollable(boolean scrollable) { mHeaderViewsScrollable = scrollable; } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { return !(!mHeaderViewsScrollable && isInHeaderView(ev)) && super.onInterceptTouchEvent(ev); } private boolean isInHeaderView(MotionEvent ev) { boolean result = false; int lastHeaderViewPosition = getHeaderViewsCount() - 1; int firstVisiblePosition = getFirstVisiblePosition(); int lastVisiblePosition = getLastVisiblePosition(); if (firstVisiblePosition <= lastHeaderViewPosition) { if (lastHeaderViewPosition <= lastVisiblePosition) { View lastHeaderView = getChildAt(lastHeaderViewPosition - firstVisiblePosition); result = ev.getY() < lastHeaderView.getBottom(); } else { result = true; } } return result; }}