From 416f4bce4153d9e733285a0104126ae8d023deab Mon Sep 17 00:00:00 2001 From: rabtman Date: Thu, 4 Feb 2021 17:24:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=99=BA=E8=83=BD=E7=AD=89?= =?UTF-8?q?=E5=AE=BD=E5=88=A4=E6=96=AD=E4=B8=8D=E5=87=86=E7=A1=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/angcyo/tablayout/DslTabLayout.kt | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/TabLayout/src/main/java/com/angcyo/tablayout/DslTabLayout.kt b/TabLayout/src/main/java/com/angcyo/tablayout/DslTabLayout.kt index eacae94..0a8697a 100644 --- a/TabLayout/src/main/java/com/angcyo/tablayout/DslTabLayout.kt +++ b/TabLayout/src/main/java/com/angcyo/tablayout/DslTabLayout.kt @@ -549,23 +549,27 @@ open class DslTabLayout( //智能等宽判断 if (itemAutoEquWidth) { - var childMaxWidth = 0 //所有child宽度总和 + var childMaxWidth = 0 //child最大宽度 visibleChildList.forEachIndexed { index, child -> val lp: LayoutParams = child.layoutParams as LayoutParams measureChild(child, widthMeasureSpec, heightMeasureSpec) - childMaxWidth += lp.leftMargin + lp.rightMargin + child.measuredWidth + var curChildWidth = lp.leftMargin + lp.rightMargin + child.measuredWidth if (drawDivider) { if (tabDivider?.haveBeforeDivider(index, visibleChildList.size) == true) { - childMaxWidth += dividerWidthExclude + curChildWidth += dividerWidthExclude } if (tabDivider?.haveAfterDivider(index, visibleChildList.size) == true) { - childMaxWidth += dividerWidthExclude + curChildWidth += dividerWidthExclude } } + + if (curChildWidth > childMaxWidth) { + childMaxWidth = curChildWidth + } } - itemIsEquWidth = childMaxWidth <= widthSize + itemIsEquWidth = (childMaxWidth * visibleChildList.size) <= widthSize } //等宽时, child宽度的测量模式 @@ -807,23 +811,27 @@ open class DslTabLayout( //智能等宽判断 if (itemAutoEquWidth) { - var childMaxHeight = 0 //所有child高度总和 + var childMaxHeight = 0 //child最大高度 visibleChildList.forEachIndexed { index, child -> val lp: LayoutParams = child.layoutParams as LayoutParams measureChild(child, widthMeasureSpec, heightMeasureSpec) - childMaxHeight += lp.topMargin + lp.bottomMargin + child.measuredHeight + var curChildHeight = lp.topMargin + lp.bottomMargin + child.measuredHeight if (drawDivider) { if (tabDivider?.haveBeforeDivider(index, visibleChildList.size) == true) { - childMaxHeight += dividerHeightExclude + curChildHeight += dividerHeightExclude } if (tabDivider?.haveAfterDivider(index, visibleChildList.size) == true) { - childMaxHeight += dividerHeightExclude + curChildHeight += dividerHeightExclude } } + + if (curChildHeight > childMaxHeight) { + childMaxHeight = curChildHeight + } } - itemIsEquWidth = childMaxHeight <= heightSize + itemIsEquWidth = (childMaxHeight * visibleChildList.size) <= heightSize } //等宽时, child高度的测量模式