Sami Shorman
Sami Shorman

Reputation: 158

Extra end and start margin with chips

How can i remove extra margins or (spacing) from chips inside chip group?

below is all things that i try in styles,code and xml none of these work for me.

Here is how it's looks: enter image description here

And here is what i try and my code:

   <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>

Here is how i add chips to the group

     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
    }


And here is my chips style

 <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>

Upvotes: 0

Views: 535

Answers (1)

Sami Shorman
Sami Shorman

Reputation: 158

I found this answer from material-components/material-components-android repo and worked for me.

there's a flag on by default to ensure that chips meet Android's minimum recommended touch size. You can disable it by setting ensureMinTouchTargetSize == false

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

Upvotes: 1

Related Questions