Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

处理智能等宽判断不准确问题 #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions TabLayout/src/main/java/com/angcyo/tablayout/DslTabLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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宽度的测量模式
Expand Down Expand Up @@ -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高度的测量模式
Expand Down