Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

426
Views
Composición de Jetpack: es posible configurar la altura de DropdownMenu para mostrar el siguiente elemento

Estoy usando DropdownMenu en Jetpack Compose, pero tengo el problema de que muchos usuarios no entienden que el menú contiene más información para que puedan desplazarse por la lista. Recibo mucho apoyo de que les faltan cosas de la lista. Especialmente en algunos idiomas, alinea muy bien la altura con un elemento, por lo que no ve que hay más elementos.

¿Hay alguna manera de configurar automáticamente la altura del menú desplegable (sin importar el idioma) para que muestre la mitad de un elemento en la parte inferior, para que los usuarios entiendan que pueden desplazarse por la lista?

Creo el menú usando estos modificadores:

 DropdownMenu( expanded = expanded, onDismissRequest = { expanded = false }, modifier = Modifier.requiredSizeIn(maxHeight = 330.dp) ) { items.forEachIndexed { index, item -> DropdownMenuItem(onClick = { onSelected(index, item.data) selectedIndex = index expanded = false }) { ... }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Estoy de acuerdo en que esta es una buena función, le sugiero que cree una solicitud de función en el rastreador de problemas de Compose.

Aquí hay una solución por ahora, puede obtener las alturas de sus elementos usando Modifier.onSizeChanged y actualizar su restricción maxHeight de esta manera:

 @Composable fun TestScreen( ) { var expanded by remember { mutableStateOf(true) } val items = List(10) { it.toString() } val itemHeights = remember { mutableStateMapOf<Int, Int>() } val baseHeight = 330.dp val density = LocalDensity.current val maxHeight = remember(itemHeights.toMap()) { if (itemHeights.keys.toSet() != items.indices.toSet()) { // if we don't have all heights calculated yet, return default value return@remember baseHeight } val baseHeightInt = with(density) { baseHeight.toPx().toInt() } // top+bottom system padding var sum = with(density) { DropdownMenuVerticalPadding.toPx().toInt() } * 2 for ((i, itemSize) in itemHeights.toSortedMap()) { sum += itemSize if (sum >= baseHeightInt) { return@remember with(density) { (sum - itemSize / 2).toDp() } } } // all items fit into base height baseHeight } DropdownMenu( expanded = expanded, onDismissRequest = { expanded = false }, modifier = Modifier.requiredSizeIn(maxHeight = maxHeight) ) { items.forEachIndexed { index, item -> DropdownMenuItem( onClick = { onSelected(index, item.data) selectedIndex = index expanded = false }, modifier = Modifier.onSizeChanged { itemHeights[index] = it.height } ) { Text("Hello $index", modifier = Modifier.padding(30.dp)) } } } } private val DropdownMenuVerticalPadding = 8.dp

ps DropdownMenuVerticalPadding es una constante Material tomada del código fuente .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!