mTreasureBoxView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
mTreasureBoxView.startEditMode(position);
return true;
}
});
I have set child view focusable = false. but not fix that problem. this phones has this problem. 三星A7000(5.0.2) 、华为GEM-703L(5.1.1)、 LG-h818B(5.1)、HTC E9+(5.0.0)
this is parent view SlidingUPPanel . it's dispatchTouchEvent();
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (!isEnabled() || !isTouchEnabled() || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN) || isDragSetting()) {
return super.dispatchTouchEvent(ev);
}
final float y = ev.getY();
final float x = ev.getX();
Log.i(TAG, "dispatchTouchEvent: action " + action);
if (action == MotionEvent.ACTION_DOWN) {
mIsScrollableViewHandlingTouch = false;
mPrevMotionY = y;
} else if (action == MotionEvent.ACTION_MOVE) {
float dy = y - mPrevMotionY;
mPrevMotionY = y;
if (!isViewHit(mScrollableView, (int) mInitialMotionX, (int) mInitialMotionY)) {
return super.dispatchTouchEvent(ev);
}
//增加滑动距离判断,必须滑动到顶部才能让ScrollableView控制touch事件
if (getScrollPosition(mScrollableView, mIsSlidingUp) > 0) {
mIsScrollableViewHandlingTouch = true;
return super.dispatchTouchEvent(ev);
}
if (!isExpanding(dy)) { // Collapsing
if (mIsScrollableViewHandlingTouch) {
MotionEvent up = MotionEvent.obtain(ev);
up.setAction(MotionEvent.ACTION_CANCEL);
super.dispatchTouchEvent(up);
up.recycle();
ev.setAction(MotionEvent.ACTION_DOWN);
}
mIsScrollableViewHandlingTouch = false;
return this.onTouchEvent(ev);
} else if (isExpanding(dy)) { // Expanding
if (mSlideOffset < mAnchorPoint) {
mIsScrollableViewHandlingTouch = false;
return this.onTouchEvent(ev);
}
if (!mIsScrollableViewHandlingTouch && mDragHelper.isDragging()) {
mDragHelper.cancel();
ev.setAction(MotionEvent.ACTION_DOWN);
}
//增加滑动距离判断,必须滑动到顶部才能让ScrollableView控制touch事件
if (mSlideOffset >= mAnchorPoint) {
mIsScrollableViewHandlingTouch = true;
}
return super.dispatchTouchEvent(ev);
}
} else if (action == MotionEvent.ACTION_UP) {
if (mIsScrollableViewHandlingTouch) {
mDragHelper.setDragState(ViewDragHelper.STATE_IDLE);
}
}
return super.dispatchTouchEvent(ev);
}
and this is getScrollPosition() method . for determine if should dispatchTouchEvent to next view ..
/**
* 判断是否可以进行拖动操作
*
* @param scrollableView 目前只支持百宝箱TreasureBoxView 的适配
* @param isSlidingUp
* @return position > 0 可以进行滑动
*/
private int getScrollPosition(View scrollableView, boolean isSlidingUp) {
if (scrollableView instanceof TreasureBoxView && ((TreasureBoxView) scrollableView).getChildCount() > 0) {
TreasureBoxView lv = ((TreasureBoxView) scrollableView);
if (lv.getAdapter() == null) {
return 0;
}
//编辑默认过程中
if (lv.isEditMode()) {
return 1;
}
if (isSlidingUp) {
View firstChild = lv.getChildAt(0);
return lv.getFirstVisiblePosition() * firstChild.getHeight() - firstChild.getTop();
} else {
View lastChild = lv.getChildAt(lv.getChildCount() - 1);
return (lv.getAdapter().getCount() - lv.getLastVisiblePosition() - 1) * lastChild.getHeight() + lastChild.getBottom() - lv.getBottom();
}
} else {
return 0;
}
}
I found a special thing. if getScrollPosition() >= 0 , it works ` but that may not let my slidingUpPanelView scroll down. can't do that.