Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I position/size objects inside an Android jetpack compose Box by percent?

Tags:

android

I'm just starting with Android jetpack compose and would like to place a button in a Box and have the button be 20% as wide as the width of the Box and have it be 50% of the width of the Box. In the old ContraintLayout, I could do this with layout_constraintGuide_percent.

like image 974
Garths KidStuff Avatar asked Sep 06 '25 19:09

Garths KidStuff


1 Answers

You can set the width and height with respect to parent like this,

Button(modifier = Modifier.
       fillMaxWidth(0.5f)) //50% width as the parent 
like image 59
RaBaKa 78 Avatar answered Sep 08 '25 12:09

RaBaKa 78