material-components / material-components/material-components-android
[Exposed dropdown menus]: Layout expands to width of menu content, not the width of the text that will be displayed.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 17.4k
- Fork
- 3.2k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Description: When using an adapter to provide more complex content to an exposed drop down menu, the width of the TextInputLayout is expanded to the width of the menu, not the width of the longest content that will be shown in TextInputLayout.
This is probably easier to explain with screenshots.
This is the screenshot of an exposed drop down menu with three items, "Show", "Warn", and "Hide", set using setOptions().
This is what I expect.
However, I want to show the user additional information about each choice. The labels are deliberately short because there isn't much screen real estate available. So I have a trivial adapter that uses a two-line view, like this:
data class FilterDescription(val title: String, val descr: String) {
override fun toString() = title
}
val adapter = object : ArrayAdapter<FilterDescription>(
requireContext(),
android.R.layout.simple_list_item_2,
android.R.id.text1,
) {
val items = listOf( /* FilterDescription objects here */ )
init {
addAll(items)
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
val view = super.getView(position, convertView, parent)
val text1 = view.findViewById<TextView>(android.R.id.text1)
val text2 = view.findViewById<TextView>(android.R.id.text2)
getItem(position)?.let { item ->
text1.text = item.title
text2.text = item.descr
}
return view
}
}
If I set this adapter the menu displays two lines per item as expected. However, the width of the TextInputLayout is now the width of the longest descr. Like this with the menu open:
and this with the menu closed:
Expected behavior: The layout should be the maximum width of the content that will be shown in it, not the maximum width of the pop up menu.
Source code: As above.
Android API version: 31
Material Library version: 1.12.0
Device: Emulator
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il problema su Android API 31 con Material Library 1.12.0 usando l’adapter Kotlin fornito e il menu a discesa esposto. Esamina il comportamento di misurazione della larghezza del menu; il lavoro è completo quando il TextInputLayout chiuso viene dimensionato in base al contenuto visualizzato anziché alle descrizioni più lunghe dell’adapter, mentre il menu continua a mostrare entrambe le righe.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- android, kotlin
- Ambito
- mobile-dev
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100