Chip() 没有正确地水平调整大小
Chip() not correctly resizing horizontally
所以我有这个扩展功能,应该可以创建一个芯片。我希望芯片比正常的小。
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
}
如您所见,文本前后的填充或其他内容是错误的。芯片垂直缩放正确,但宽度调整不正确。
有人知道为什么这不起作用吗?
提前致谢。
好的,我明白了。
您必须设置所有这些参数才能真正缩小它:
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
所以我有这个扩展功能,应该可以创建一个芯片。我希望芯片比正常的小。
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
}
如您所见,文本前后的填充或其他内容是错误的。芯片垂直缩放正确,但宽度调整不正确。
有人知道为什么这不起作用吗?
提前致谢。
好的,我明白了。 您必须设置所有这些参数才能真正缩小它:
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