【发布时间】:2021-10-15 21:17:51
【问题描述】:
如何从芯片组内的芯片中去除多余的边距或(间距)?
以下是我在样式、代码和 xml 中尝试的所有东西,这些都不适合我。
这是我尝试的和我的代码:
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tagsRecyclerView">
<com.google.android.material.chip.ChipGroup
android:id="@+id/subTagsChips"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleLine="true">
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
这是我如何将筹码添加到组中的方法
private fun generateChips(chipsList:ArrayList<SubTag>):ArrayList<Chip>{
val list = arrayListOf<Chip>()
chipsList.forEach { subTag ->
val generatedChip = Chip(requireContext())
generatedChip.apply {
text = subTag.tag
setTextColor(ContextCompat.getColorStateList(requireContext(),R.color.chip_text_color))
val drawable = ChipDrawable.createFromAttributes(context, null, 0,
R.style.ChipsStyle)
setChipDrawable(drawable)
}
list.add(generatedChip)
}
return list
}
这是我的筹码风格
<style name="ChipsStyle" parent="Widget.MaterialComponents.Chip.Choice">
<item name="chipBackgroundColor">@color/chip_state_bc</item>
<item name="checkedIconTint">@color/white</item>
<item name="chipCornerRadius">5dp</item>
<item name="chipSpacingHorizontal">0dp</item>
<item name="android:layout_margin">0dp</item>
<item name="ensureMinTouchTargetSize">false</item>
</style>
【问题讨论】:
-
我对此没有经验,但我认为您应该在
ChipGroup中使用app:chipSpacingHorizontal属性,而不是在Chips样式中来控制芯片间距。请检查Chip spacing部分material.io/components/chips/android#using-chips -
我试过了......但它不起作用,我在 xml 中以编程方式尝试过
标签: java android kotlin material-design android-chips