Skip to content

Commit

Permalink
修正在 ConstraintLayout 中高度可能不正確的問題
Browse files Browse the repository at this point in the history
  • Loading branch information
aids61517 committed Jul 13, 2019
1 parent a227ddd commit 41d262a
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EasyRatingView @JvmOverloads constructor(

var rating: Float = 0f
set(value) {
field = value
field = if (value > numberStars) numberStars.toFloat() else value
invalidate()
}

Expand Down Expand Up @@ -65,23 +65,18 @@ class EasyRatingView @JvmOverloads constructor(

val widthMode = MeasureSpec.getMode(widthMeasureSpec)
val widthSize = MeasureSpec.getSize(widthMeasureSpec)
val heightMode = MeasureSpec.getMode(heightMeasureSpec)
val heightSize = MeasureSpec.getSize(heightMeasureSpec)

var realWidth = widthSize
var realHeight = heightSize
val drawableWidth = emptyDrawable.intrinsicWidth
val drawableHeight = emptyDrawable.intrinsicHeight
val needWidth = numberStars * drawableWidth + (numberStars - 1) * spacing
if (widthMode == MeasureSpec.AT_MOST) {
realWidth = if (needWidth < realWidth) needWidth else realWidth
realWidth += paddingStart + paddingEnd
}
if (heightMode == MeasureSpec.AT_MOST) {
realHeight = if (drawableHeight < realHeight) drawableHeight else realHeight
realHeight += paddingTop + paddingBottom
}

val expectHeight = drawableHeight + paddingTop + paddingBottom
val realHeight = resolveSizeAndState(expectHeight, heightMeasureSpec, 0)
setMeasuredDimension(realWidth, realHeight)
}

Expand Down

0 comments on commit 41d262a

Please sign in to comment.