Created
August 29, 2017 11:15
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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