bugfix: disposable. #881

This commit is contained in:
cgspine
2020-04-22 16:04:27 +08:00
parent 0f06eafc0e
commit 907d581eaa
2 changed files with 71 additions and 13 deletions
@@ -68,6 +68,8 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
for (View view : mTempDisposableChildList) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.width = 0;
lp.leftMargin = 0;
lp.rightMargin = 0;
}
} else {
int usefulWidth = widthSize - usedWidth;
@@ -87,11 +89,13 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
for (View view : mTempDisposableChildList) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.width = 0;
lp.leftMargin = 0;
lp.rightMargin = 0;
}
} else if (miniWidthChildTotalWidth < usefulWidth) {
// there is a space for disposableChildList
if (!mTempDisposableChildList.isEmpty()) {
dispatchSpaceToDisposableChildList(mTempDisposableChildList,
dispatchSpaceToDisposableChildList(mTempDisposableChildList, widthMeasureSpec, heightMeasureSpec,
usefulWidth - miniWidthChildTotalWidth);
}
} else {
@@ -99,6 +103,8 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
for (View view : mTempDisposableChildList) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.width = 0;
lp.leftMargin = 0;
lp.rightMargin = 0;
}
if (usefulWidth < miniWidthChildTotalWidth && !mTempMiniWidthChildList.isEmpty()) {
dispatchSpaceToMiniWidthChildList(mTempMiniWidthChildList, usefulWidth, miniWidthChildTotalWidth);
@@ -124,6 +130,8 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
for (View view : mTempDisposableChildList) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.height = 0;
lp.topMargin = 0;
lp.bottomMargin = 0;
}
} else {
int usefulSpace = heightSize - usedHeight;
@@ -143,11 +151,13 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
for (View view : mTempDisposableChildList) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.height = 0;
lp.topMargin = 0;
lp.bottomMargin = 0;
}
} else if (miniSizeChildTotalLength < usefulSpace) {
// there is a space for disposableChildList
if (!mTempDisposableChildList.isEmpty()) {
dispatchSpaceToDisposableChildList(mTempDisposableChildList,
dispatchSpaceToDisposableChildList(mTempDisposableChildList, widthMeasureSpec, heightMeasureSpec,
usefulSpace - miniSizeChildTotalLength);
}
} else {
@@ -155,6 +165,8 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
for (View view : mTempDisposableChildList) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
lp.width = 0;
lp.topMargin = 0;
lp.bottomMargin = 0;
}
if (usefulSpace < miniSizeChildTotalLength && !mTempMiniWidthChildList.isEmpty()) {
dispatchSpaceToMiniWidthChildList(mTempMiniWidthChildList, usefulSpace, miniSizeChildTotalLength);
@@ -207,22 +219,55 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
return usedSize;
}
protected void dispatchSpaceToDisposableChildList(ArrayList<View> childList, int usefulSpace) {
protected void dispatchSpaceToDisposableChildList(ArrayList<View> childList, int widthMeasureSpec, int heightMeasureSpec, int usefulSpace) {
for (View view : childList) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
if (getOrientation() == HORIZONTAL) {
if(usefulSpace <= 0){
lp.leftMargin = 0;
lp.rightMargin = 0;
lp.width = 0;
}
usefulSpace -= lp.leftMargin - lp.rightMargin;
if(usefulSpace > 0){
view.measure(
MeasureSpec.makeMeasureSpec(usefulSpace, MeasureSpec.AT_MOST),
getChildMeasureSpec(heightMeasureSpec, getPaddingTop() + getPaddingBottom(), lp.height));
if(view.getMeasuredWidth() >= usefulSpace){
lp.width = usefulSpace;
usefulSpace = 0;
}else{
usefulSpace -= view.getMeasuredWidth();
}
}else{
lp.leftMargin = 0;
lp.rightMargin = 0;
lp.width = 0;
}
} else {
if(usefulSpace <= 0){
lp.topMargin = 0;
lp.bottomMargin = 0;
lp.height = 0;
}
usefulSpace -= lp.topMargin - lp.bottomMargin;
}
}
int avgSpace = Math.max(0, usefulSpace / childList.size());
for (View view : childList) {
LayoutParams lp = (LayoutParams) view.getLayoutParams();
if (getOrientation() == HORIZONTAL) {
lp.width = avgSpace;
} else {
lp.height = avgSpace;
if(usefulSpace > 0){
view.measure(
getChildMeasureSpec(widthMeasureSpec, getPaddingLeft() + getPaddingRight(), lp.width),
MeasureSpec.makeMeasureSpec(usefulSpace, MeasureSpec.AT_MOST));
if(view.getMeasuredHeight() >= usefulSpace){
lp.height = usefulSpace;
usefulSpace = 0;
}else{
usefulSpace -= view.getMeasuredHeight();
}
}else{
lp.topMargin = 0;
lp.bottomMargin = 0;
lp.height = 0;
}
}
}
}
@@ -289,6 +334,10 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
private int backupWidth = Integer.MIN_VALUE;
private int backupHeight = Integer.MIN_VALUE;
private int backupLeftMargin = 0;
private int backupRightMargin = 0;
private int backupTopMargin = 0;
private int backupBottomMargin = 0;
public LayoutParams(Context c, AttributeSet attrs) {
@@ -347,13 +396,21 @@ public class QMUIPriorityLinearLayout extends QMUILinearLayout {
void backupOrRestore() {
if (backupWidth == Integer.MIN_VALUE) {
backupWidth = width;
backupLeftMargin = leftMargin;
backupRightMargin = rightMargin;
} else {
width = backupWidth;
leftMargin = backupLeftMargin;
rightMargin = backupRightMargin;
}
if (backupHeight == Integer.MIN_VALUE) {
backupHeight = height;
backupTopMargin = topMargin;
backupBottomMargin = bottomMargin;
} else {
height = backupHeight;
topMargin = backupTopMargin;
bottomMargin = backupBottomMargin;
}
}
}
@@ -299,7 +299,8 @@
android:layout_marginRight="4dp"
android:ellipsize="end"
android:singleLine="true"
android:text="测试文案测试文案测试"/>
android:text="测试文案测试文案测试"
app:qmui_layout_priority="disposable"/>
<TextView
android:layout_width="wrap_content"