Я работаю над макетом с 3-колуанами, и я хочу повернуть содержание одного из столбцов на 90 градусов: < /p>
Я попытался обменивать ширину и высоту и настраивать размещение контента, но без успеха.
Вот проблема: когда коробка, которую я хочу повернуть, занимает 50% ширины экрана, она работает, как и ожидалось. Однако, если коробка больше или меньше 50%, я сталкиваюсь с зазором внизу. ? < /p>
Вот мой полный файл: < /p>
@Composable
fun Layout() {
Row(
modifier = Modifier
.fillMaxSize()
.background(Color.Red)
) {
Row(
modifier = Modifier
.fillMaxSize()
) {
Box(
modifier = Modifier
.weight(1f)
.fillMaxSize()
.rotate(90f)
.swapDimensions()
.background(Color.Blue)
.background(Color.LightGray)
) {
Column(
modifier = Modifier
) {
Column(modifier = Modifier.background(Color.Magenta).fillMaxWidth()) {
Text(text = "All content in this box has to be rotated 90deg")
}
Column(modifier = Modifier.background(Color.LightGray)) {
Text(text = "Text 2")
}
}
}
Column(
modifier = Modifier
.weight(1f)
.fillMaxSize()
) {
Box(
modifier = Modifier
.weight(1f)
.fillMaxSize()
.background(Color.Green)
) {
Text(text = "This content is normal")
}
Box(
modifier = Modifier
.weight(1f)
.fillMaxSize()
.background(Color.Yellow)
) {
Text(text = "This content is normal")
}
}
Column(
modifier = Modifier
.weight(1f)
.fillMaxSize()
) {
Box(
modifier = Modifier
.weight(1f)
.fillMaxSize()
.background(Color.Magenta)
) {
Text(text = "This content is normal")
}
Box(
modifier = Modifier
.weight(1f)
.fillMaxSize()
.background(Color.Blue)
) {
Text(text = "This content is normal")
}
}
}
}
}
fun Modifier.swapDimensions() = layout { measurable, constraints ->
val placeable = measurable.measure(constraints)
val originalWidth = placeable.width
val originalHeight = placeable.height
val swappedWidth = originalHeight
val swappedHeight = originalWidth
layout(
swappedWidth,
swappedHeight
) {
placeable.place(
x = (swappedWidth - originalHeight) / 2,
y = (swappedHeight - originalWidth) / 2
)
}
}
@Preview(
name = "Landscape Preview",
device = "spec:width=800dp, height=400dp",
showBackground = true
)
@Composable
fun PreviewLayout() {
Layout()
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... composable