Fix hideItem radius bug

Optimize layout code
This commit is contained in:
2022-03-21 19:17:38 +08:00
parent dc3beae036
commit e05806f335
4 changed files with 20 additions and 23 deletions

View File

@@ -26,41 +26,36 @@ public class AutoLinefeedLayout extends ViewGroup {
private void layoutHorizontal() {
final int count = getChildCount();
final int lineWidth = getMeasuredWidth() - getPaddingLeft()
- getPaddingRight();
final int lineWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
int paddingTop = getPaddingTop();
int childTop = 0;
int childTop;
int childLeft = getPaddingLeft();
int availableLineWidth = lineWidth;
int maxLineHight = 0;
int maxLineHeight = 0;
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
if (child == null) {
continue;
} else if (child.getVisibility() != GONE) {
if (child != null && child.getVisibility() != GONE) {
final int childWidth = child.getMeasuredWidth();
final int childHeight = child.getMeasuredHeight();
if (availableLineWidth < childWidth) {
availableLineWidth = lineWidth;
paddingTop = paddingTop + maxLineHight;
paddingTop = paddingTop + maxLineHeight;
childLeft = getPaddingLeft();
maxLineHight = 0;
maxLineHeight = 0;
}
childTop = paddingTop;
setChildFrame(child, childLeft, childTop, childWidth,
childHeight);
setChildFrame(child, childLeft, childTop, childWidth, childHeight);
childLeft += childWidth;
availableLineWidth = availableLineWidth - childWidth;
maxLineHight = Math.max(maxLineHight, childHeight);
maxLineHeight = Math.max(maxLineHeight, childHeight);
}
}
}
private void setChildFrame(View child, int left, int top, int width,
int height) {
private void setChildFrame(View child, int left, int top, int width, int height) {
child.layout(left, top, left + width, top + height);
}
@@ -73,8 +68,7 @@ public class AutoLinefeedLayout extends ViewGroup {
}
if (heightMode == MeasureSpec.AT_MOST||heightMode == MeasureSpec.UNSPECIFIED) {
final int width = MeasureSpec.getSize(widthMeasureSpec);
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(
getDesiredHeight(width), MeasureSpec.EXACTLY));
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(getDesiredHeight(width), MeasureSpec.EXACTLY));
} else {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

View File

@@ -60,8 +60,6 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener{
content = new LinearLayout(context);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
/*content.setShowDividers(SHOW_DIVIDER_BEGINNING|SHOW_DIVIDER_MIDDLE);
content.setDividerDrawable(ContextCompat.getDrawable(context,R.drawable.item_divider));*/
content.setOrientation(VERTICAL);
addView(content,layoutParams);
}
@@ -95,7 +93,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener{
content.setLayoutParams(layoutParams);
});
showAnimator.addListener(new AnimatorListenerAdapter() {
@Override
@SuppressLint("UseCompatLoadingForDrawables")
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
LinearLayout linearLayout = defaultView.findViewById(R.id.foldLayoutLinearLayout);
@@ -110,11 +108,14 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener{
content.setLayoutParams(layoutParams);
});
hideAnimator.addListener(new AnimatorListenerAdapter() {
@SuppressLint("UseCompatLoadingForDrawables")
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
LinearLayout linearLayout = defaultView.findViewById(R.id.foldLayoutLinearLayout);
linearLayout.setBackground(getResources().getDrawable(R.drawable.top_bottom_radius_background));
if (!isShow) {
LinearLayout linearLayout = defaultView.findViewById(R.id.foldLayoutLinearLayout);
linearLayout.setBackground(getResources().getDrawable(R.drawable.top_bottom_radius_background));
}
}
});
init = true;
@@ -148,6 +149,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener{
content.setLayoutParams(layoutParams);
}
@SuppressLint("UseCompatLoadingForDrawables")
public void showItem() {
isShow = true;
showAnimator.start();
@@ -157,6 +159,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener{
animatedVectorDrawable.start();
}
@SuppressLint("UseCompatLoadingForDrawables")
public void hideItem() {
isShow = false;
hideAnimator.start();

View File

@@ -3,7 +3,7 @@
<style name="Theme.OxygenToolbox" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimaryVariant">@color/purple_200</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>

View File

@@ -3,7 +3,7 @@
<style name="Theme.OxygenToolbox" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorPrimaryVariant">@color/purple_500</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>