【问题标题】:Extra end and start margin with chips筹码的额外结束和开始保证金
【发布时间】: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


【解决方案1】:

我从 ma​​terial-components/material-components-android 存储库中找到了这个答案并为我工作。

默认情况下会打开一个标志,以确保芯片符合 Android 建议的最小触摸尺寸。您可以通过设置 ensureMinTouchTargetSize == false 来禁用它

来源:https://github.com/material-components/material-components-android/issues/1445

【讨论】:

    猜你喜欢
    • 2018-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多