Skip to content

Instantly share code, notes, and snippets.

@pokk
Created August 29, 2017 11:15
Show Gist options
  • Save pokk/14ccc9342b87d165b586732fcbd90d6c to your computer and use it in GitHub Desktop.
Save pokk/14ccc9342b87d165b586732fcbd90d6c to your computer and use it in GitHub Desktop.
A easy way to set onMeasure function. Of course if you wanna customize more, you can do more things.
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
// Measure all of children's width & height.
this.measureChildren(widthMeasureSpec, heightMeasureSpec)
// Measure width & height of this view_group's layout(layout_width or layout_height will be `match_parent`
// no matter what we set `wrap_content` or `match_patent` when we're using getDefaultSize).
// We'll reset this method by another way for achieving `wrap_content`.
val mini = minOf(getDefaultSize(suggestedMinimumWidth, widthMeasureSpec), getDefaultSize(suggestedMinimumHeight, heightMeasureSpec))
this.setMeasuredDimension(mini, mini)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment