mirror of
https://github.com/Tencent/QMUI_Android.git
synced 2026-10-19 05:21:30 +08:00
check layout after layout
This commit is contained in:
+12
-1
@@ -63,6 +63,12 @@ public abstract class QMUIContinuousNestedBottomDelegateLayout extends QMUIFrame
|
||||
private final int[] mScrollOffset = new int[2];
|
||||
private Rect mTempRect = new Rect();
|
||||
private int mNestedOffsetY = 0;
|
||||
private Runnable mCheckLayoutAction = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkLayout();
|
||||
}
|
||||
};
|
||||
|
||||
public QMUIContinuousNestedBottomDelegateLayout(Context context) {
|
||||
this(context, null);
|
||||
@@ -177,7 +183,12 @@ public abstract class QMUIContinuousNestedBottomDelegateLayout extends QMUIFrame
|
||||
|
||||
mHeaderViewOffsetHelper.onViewLayout();
|
||||
mContentViewOffsetHelper.onViewLayout();
|
||||
checkLayout();
|
||||
postCheckLayout();
|
||||
}
|
||||
|
||||
public void postCheckLayout() {
|
||||
removeCallbacks(mCheckLayoutAction);
|
||||
post(mCheckLayoutAction);
|
||||
}
|
||||
|
||||
public void checkLayout() {
|
||||
|
||||
+21
-10
@@ -37,6 +37,12 @@ public class QMUIContinuousNestedScrollLayout extends CoordinatorLayout implemen
|
||||
private QMUIContinuousNestedTopAreaBehavior mTopAreaBehavior;
|
||||
private QMUIContinuousNestedBottomAreaBehavior mBottomAreaBehavior;
|
||||
private List<OnScrollListener> mOnScrollListeners = new ArrayList<>();
|
||||
private Runnable mCheckLayoutAction = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkLayout();
|
||||
}
|
||||
};
|
||||
|
||||
public QMUIContinuousNestedScrollLayout(@NonNull Context context) {
|
||||
super(context);
|
||||
@@ -152,11 +158,16 @@ public class QMUIContinuousNestedScrollLayout extends CoordinatorLayout implemen
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||
super.onLayout(changed, l, t, r, b);
|
||||
checkLayout();
|
||||
postCheckLayout();
|
||||
}
|
||||
|
||||
private void checkLayout(){
|
||||
if(mTopView == null || mBottomView == null){
|
||||
public void postCheckLayout() {
|
||||
removeCallbacks(mCheckLayoutAction);
|
||||
post(mCheckLayoutAction);
|
||||
}
|
||||
|
||||
public void checkLayout() {
|
||||
if (mTopView == null || mBottomView == null) {
|
||||
return;
|
||||
}
|
||||
int topCurrent = mTopView.getCurrentScroll();
|
||||
@@ -164,23 +175,23 @@ public class QMUIContinuousNestedScrollLayout extends CoordinatorLayout implemen
|
||||
int offsetCurrent = -mTopAreaBehavior.getTopAndBottomOffset();
|
||||
int offsetRange = getOffsetRange();
|
||||
int bottomCurrent = mBottomView.getCurrentScroll();
|
||||
if(topCurrent < topRange && offsetCurrent > 0){
|
||||
if (topCurrent < topRange && offsetCurrent > 0) {
|
||||
int remain = topRange - topCurrent;
|
||||
if(offsetCurrent >= remain){
|
||||
if (offsetCurrent >= remain) {
|
||||
mTopView.consumeScroll(Integer.MAX_VALUE);
|
||||
mTopAreaBehavior.setTopAndBottomOffset(remain - offsetCurrent);
|
||||
}else{
|
||||
} else {
|
||||
mTopView.consumeScroll(offsetCurrent);
|
||||
mTopAreaBehavior.setTopAndBottomOffset(0);
|
||||
}
|
||||
}
|
||||
|
||||
if(bottomCurrent > 0 && offsetCurrent < offsetRange){
|
||||
if (bottomCurrent > 0 && offsetCurrent < offsetRange) {
|
||||
int over = offsetRange - offsetCurrent;
|
||||
if(over >= bottomCurrent){
|
||||
if (over >= bottomCurrent) {
|
||||
mBottomView.consumeScroll(Integer.MIN_VALUE);
|
||||
mTopAreaBehavior.setTopAndBottomOffset(-bottomCurrent - offsetCurrent);
|
||||
}else{
|
||||
} else {
|
||||
mBottomView.consumeScroll(-over);
|
||||
mTopAreaBehavior.setTopAndBottomOffset(-offsetRange);
|
||||
}
|
||||
@@ -332,7 +343,7 @@ public class QMUIContinuousNestedScrollLayout extends CoordinatorLayout implemen
|
||||
|
||||
@Override
|
||||
public boolean dispatchTouchEvent(MotionEvent ev) {
|
||||
if(ev.getAction() == MotionEvent.ACTION_DOWN){
|
||||
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
stopScroll();
|
||||
}
|
||||
return super.dispatchTouchEvent(ev);
|
||||
|
||||
+23
-4
@@ -47,6 +47,12 @@ public class QMUIContinuousNestedTopDelegateLayout extends FrameLayout implement
|
||||
private int mOffsetRange = 0;
|
||||
private final NestedScrollingParentHelper mParentHelper;
|
||||
private final NestedScrollingChildHelper mChildHelper;
|
||||
private Runnable mCheckLayoutAction = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkLayout();
|
||||
}
|
||||
};
|
||||
|
||||
public QMUIContinuousNestedTopDelegateLayout(@NonNull Context context) {
|
||||
this(context, null);
|
||||
@@ -162,7 +168,12 @@ public class QMUIContinuousNestedTopDelegateLayout extends FrameLayout implement
|
||||
mFooterViewOffsetHelper.onViewLayout();
|
||||
mOffsetCurrent = -mFooterViewOffsetHelper.getTopAndBottomOffset();
|
||||
}
|
||||
checkLayout();
|
||||
postCheckLayout();
|
||||
}
|
||||
|
||||
public void postCheckLayout() {
|
||||
removeCallbacks(mCheckLayoutAction);
|
||||
post(mCheckLayoutAction);
|
||||
}
|
||||
|
||||
public void checkLayout() {
|
||||
@@ -176,7 +187,15 @@ public class QMUIContinuousNestedTopDelegateLayout extends FrameLayout implement
|
||||
int delegateCurrentScroll = mDelegateView.getCurrentScroll();
|
||||
int delegateScrollRange = mDelegateView.getScrollOffsetRange();
|
||||
if (delegateCurrentScroll > 0 && mHeaderView != null && mOffsetCurrent < headerOffsetRange) {
|
||||
mDelegateView.consumeScroll(Integer.MIN_VALUE);
|
||||
int over = headerOffsetRange - mOffsetCurrent;
|
||||
if (over >= delegateCurrentScroll) {
|
||||
mDelegateView.consumeScroll(Integer.MIN_VALUE);
|
||||
offsetTo(mOffsetCurrent + delegateCurrentScroll);
|
||||
} else {
|
||||
mDelegateView.consumeScroll(-over);
|
||||
offsetTo(headerOffsetRange);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mOffsetCurrent > headerOffsetRange && delegateCurrentScroll < delegateScrollRange
|
||||
@@ -184,11 +203,11 @@ public class QMUIContinuousNestedTopDelegateLayout extends FrameLayout implement
|
||||
int over = mOffsetCurrent - headerOffsetRange;
|
||||
int delegateRemain = delegateScrollRange - delegateCurrentScroll;
|
||||
if (over >= delegateRemain) {
|
||||
offsetTo(headerOffsetRange + over - delegateRemain);
|
||||
mDelegateView.consumeScroll(Integer.MAX_VALUE);
|
||||
offsetTo(headerOffsetRange + over - delegateRemain);
|
||||
} else {
|
||||
offsetTo(headerOffsetRange);
|
||||
mDelegateView.consumeScroll(over);
|
||||
offsetTo(headerOffsetRange);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user