Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compose: Place view between two backgrounds

I tried to figure out how this can be achieved in compose and have completely no idea. I want to place circle as shown on the picture. Tried to play around with Columns / Boxes without any success. Would be grateful for any tips.

enter image description here

like image 769
P.Juni Avatar asked Oct 24 '25 02:10

P.Juni


2 Answers

You can also use negative offset y, to make the view display between two views.

Column(modifier = Modifier.fillMaxSize()) {
    Row(
        modifier = Modifier
            .fillMaxWidth()
            .height(200.dp)
            .background(color = Color.Blue)
    ) {}

    Box(
        modifier = Modifier
            .fillMaxWidth()
            .height(100.dp)
            .background(color = Color.Green)
    ) {
        
        // red circle view
        Box(
            modifier = Modifier
                .align(Alignment.TopCenter)
                .offset(y = (-40).dp)
                .size(80.dp)
                .clip(CircleShape)
                .background(color = Color.Red)
        )
    }
}
like image 181
Linh Avatar answered Oct 25 '25 15:10

Linh


You can do like this

@Composable
fun CircleInsideBoxes() {
    Box(
        modifier = Modifier
            .fillMaxWidth()
            .height(200.dp) //your height for the container
    ) {
        Column(
            modifier = Modifier.fillMaxSize()
        ) {
            Box(
                modifier = Modifier
                    .fillMaxWidth()
                    .weight(1f)
                    .background(color = Color(0xFF3F48CC))
            )
            Box(
                modifier = Modifier
                    .fillMaxWidth()
                    .weight(1f)
                    .background(color = Color(0xFF00A2E8))
            )
        }
         //Outside column inside parent Box
         Box(
              modifier = Modifier
                 .clip(CircleShape)
                 .background(color = Color(0xFFED1C24))
                 .size(80.dp) //your size for the circle
                 .align(Alignment.Center)
          )
      }
  }
like image 32
RaBaKa 78 Avatar answered Oct 25 '25 16:10

RaBaKa 78



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!