Shakil Karim
05/24/2021, 11:21 AMShakil Karim
05/24/2021, 11:21 AM@Composable
fun CustomLayout(
modifier: Modifier = Modifier,
content: @Composable() () -> Unit
) {
Layout(
modifier = modifier,
content = content
) { measurables, constraints ->
val imageConstraints = Constraints.fixed(
80.dp.toPx().toInt(),
80.dp.toPx().toInt()
)
val width = constraints.maxWidth - ((imageConstraints.maxWidth * 2) + 200)
val scoreConstraints = Constraints.fixed(
width,
30.dp.toPx().toInt()
)
val imagePlacable = measurables[0].measure(imageConstraints)
val imagePlacable2 = measurables[1].measure(imageConstraints)
val scorePlacalbe = measurables[2].measure(scoreConstraints)
val locationPlacalbe = measurables[3].measure(scoreConstraints)
val datePlacable = measurables[4].measure(scoreConstraints)
layout(constraints.maxWidth, constraints.maxHeight) {
val halfHeight = imagePlacable.height / 2
val halfScreen = ((constraints.maxHeight / 2) - halfHeight)
imagePlacable.place(x = 100 , y = halfScreen)
imagePlacable2.place((constraints.maxWidth - imagePlacable.width) - 100,y = halfScreen)
scorePlacalbe.place(100 + imagePlacable.width ,
(constraints.maxHeight / 2) - (scoreConstraints.maxHeight / 2))
locationPlacalbe.place(100 + imagePlacable.width ,
(constraints.maxHeight / 2) - (scoreConstraints.maxHeight / 2) + 30.dp.toPx().toInt())
datePlacable.place(100 + imagePlacable.width ,
(constraints.maxHeight / 2) - (scoreConstraints.maxHeight / 2) - 30.dp.toPx().toInt())
}
}
}
Shakil Karim
05/24/2021, 11:22 AMfun DemoLayout() {
Card(
modifier = Modifier
.fillMaxWidth()
.height(200.dp)
.padding(16.dp),
shape = RoundedCornerShape(12.dp),
elevation = 8.dp,
backgroundColor = MaterialTheme.colors.background,
) {
CustomLayout(modifier = Modifier
.fillMaxSize()
.background(Color.Yellow)) {
Spacer(
modifier = Modifier
//.clip(CircleShape)
.background(Color.Red)
)
Spacer(
modifier = Modifier
//.clip(CircleShape)
.background(Color.Green)
)
Text(
modifier = Modifier
.background(Color.Cyan),
text = "2:2",
style = TextStyle(fontSize = 22.sp,textAlign = TextAlign.Center),
maxLines = 1
)
Text(
modifier = Modifier
.background(Color.DarkGray),
text = "Eden",
style = TextStyle(fontSize = 18.sp,textAlign = TextAlign.Center),
maxLines = 1
)
Text(
modifier = Modifier
.background(Color.DarkGray),
text = "22:10 - 22:33",
style = TextStyle(fontSize = 16.sp,textAlign = TextAlign.Center),
maxLines = 1
)
}
}
}
Cicero
05/24/2021, 11:30 AMShakil Karim
05/24/2021, 12:22 PMCicero
05/24/2021, 12:32 PMCicero
05/24/2021, 12:33 PMCicero
05/24/2021, 12:37 PMCicero
05/24/2021, 12:38 PMCicero
05/24/2021, 12:38 PMCicero
05/24/2021, 12:38 PMCicero
05/24/2021, 12:39 PMCicero
05/24/2021, 12:40 PMShakil Karim
05/24/2021, 5:46 PM