Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get MeasuredWitdh and MeasuredHeight of a Composable component?

Let's suppose I have the following composable:

Column(Modifier.fillMaxWidth()) {
        
    Text()
    Text()
    Text()

}

I would like to know how I can capture the values of measuredWidth and measuredHeight of Column. Using Android View framework style, I could take advantages of the method onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) from View.

like image 943
Agna JirKon Rx Avatar asked Oct 17 '25 06:10

Agna JirKon Rx


1 Answers

var width = 0
var hegiht = 0
Column(modifier = Modifier.onGloballyPositioned { layoutCoordinates ->
    width = layoutCoordinates.size.width
    hegiht = layoutCoordinates.size.height
}) {
    // Column body
}
like image 181
Mohammad Sianaki Avatar answered Oct 18 '25 20:10

Mohammad Sianaki