Reputation: 16496
Is there a way to take a programmatically-created button (not defined in XML) and shrink it so it matches the size of its text?
Essentially I want these buttons to be much smaller:
I have tried setting minWidth and minHeight to 0, to no avail:
val btn = Button(view.context)
btn.text = getTranslationLabel(t)
btn.minWidth = 0
btn.minHeight = 0
translationsHolder.addView(btn)
Upvotes: 0
Views: 238
Reputation: 518
So after some experimentation and searching was able to find this answer and it works https://stackoverflow.com/a/41525925/5841416. You need to set both minHeight
and minimumHeight
attributes.
button.minWidth = 0
button.minHeight = 0
button.minimumWidth = 0
button.minimumHeight = 0
Upvotes: 1