so I have this extension function which is supposed to create a chip. I want the chip to be smaller than normal.
fun createChipFromTrait(context: Context, trait: Trait): Chip {
val chip = Chip(context)
if (trait.probability != null) {
chip.text = context.getString(
R.string.hetProbability,
(trait.probability!! * 100).toInt(),
trait.toFormattedString()
)
} else {
chip.text = trait.toFormattedString()
}
if (trait.mutationFirstGene != null && trait.mutationSecondGene != null) {
chip.chipBackgroundColor = context.getColorStateList(R.color.colorSuper)
chip.setTextAppearanceResource(R.style.ChipText_Super)
} else if (trait.mutationFirstGene != null || trait.mutationSecondGene != null) {
chip.chipBackgroundColor = context.getColorStateList(R.color.colorSingleMutation)
chip.setTextAppearanceResource(R.style.ChipText_Codom)
}
chip.textSize = 12f
chip.setEnsureMinTouchTargetSize(false)
chip.setPadding(
0,
0,
0,
0,
)
chip.minimumWidth = 0
chip.minWidth = 0
chip.minHeight = 0
chip.minimumHeight = 0
chip.chipMinHeight = 0f
return chip
}
As you can see, the padding or something after and before the text is wrong. The chip is correctly scaling vertically, but the width doesn't resize correctly.
Do someone has some idea about why this doesn't work?
Thank you in advance.
Okay so, I figured it out. You have to set all these parameters to really shrink it down:
chip.setEnsureMinTouchTargetSize(false)
chip.setPadding(
5,
5,
5,
5,
)
chip.textStartPadding = 5f
chip.textEndPadding = 5f
chip.chipEndPadding = 0f
chip.chipStartPadding = 0f
chip.minWidth = 0
chip.minHeight = 0
chip.chipMinHeight = 0f