Wie ändere ich die Ausrichtung eines komponierbaren?Android

Forum für diejenigen, die für Android programmieren
Guest
 Wie ändere ich die Ausrichtung eines komponierbaren?

Post by Guest »

Ich arbeite an einem 3-Spalten-Layout und möchte den Inhalt einer der Spalten um 90 Grad drehen:
Image

Ich habe versucht, die Breite und Höhe zu vertauschen und die Platzierung des Inhalts anzupassen, aber ohne Erfolg.
Hier ist das Problem: Wenn das Feld, das ich drehen möchte, 50 % der Bildschirmbreite einnimmt, funktioniert es wie erwartet. Wenn das Feld jedoch größer oder kleiner als 50 % ist, entsteht unten eine Lücke.
Kann jemand eine Lösung vorschlagen, um sicherzustellen, dass der gedrehte Inhalt den verfügbaren Platz ausfüllt, ohne eine Lücke zu verursachen? ?
Hier ist meine vollständige Datei:

Code: Select all

@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()
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post