1.原因:
在使用ViewDragHelper時(shí),在更新ViewDragHelper內(nèi)部的view狀態(tài)時(shí)候,都會(huì)走requestLayout(),導(dǎo)致viewroot樹(shù)重新 mesure/onlayout/draw ,在layout的時(shí)候會(huì)把ViewDragHelper的view重新排版,故導(dǎo)致問(wèn)題。
2.解決:
View mVdhView;
int mVdhXOffset;
int mVdhYOffset;
@Override
public void computeScroll() {
? ? if (dragHelper.continueSettling(true)) {
? ? ? ? postInvalidateOnAnimation();
? ? } else {
? ?mVdhXOffset = mVdhView.getLeft();
? ? ? ? mVdhYOffset = mVdhView.getTop();
? ? }
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
? ? super.onLayout(changed, left, top, right, bottom);
? ? mVdhView.offsetLeftAndRight(mVdhXOffset);
? ? mVdhView.offsetTopAndBottom(mVdhYOffset);
}