Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extra space on top and bottom of android Chip material component

I'm using Chip view in my layout
Since upgraded material design component from 1.0.0 to 1.1.0, there is an extra space at the top and bottom of view
I couldn't find any document about how to remove these spaces

In material 1.0.0

enter image description here

In material 1.1.0

enter image description here

<com.google.android.material.chip.Chip
    style="@style/Widget.MaterialComponents.Chip.Action"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:text="Groceries"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
like image 905
Mahdi Javaheri Avatar asked Feb 20 '20 08:02

Mahdi Javaheri


People also ask

What is ChipGroup in Android?

A ChipGroup is used to hold multiple Chip s. By default, the chips are reflowed across multiple lines. Set the app:singleLine attribute to constrain the chips to a single horizontal line. If you do so, you'll usually want to wrap this ChipGroup in a HorizontalScrollView .

What is chip button Android?

It is a rounded button that consists of a label, an optional chip icon, and an optional close icon. A chip can either be clicked or toggled if it is checkable. Chips may be placed in a, which can be configured to layout its chips in a single horizontal line or reflowed across multiple lines.

How do I know which chip is selected Android?

ChipGroup chipGroup = findViewById(R.id.....); for (int i=0; i<chipGroup. getChildCount();i++){ Chip chip = (Chip)chipGroup. getChildAt(i); if (chip. isChecked()){ //this chip is selected..... } }


1 Answers

It is related to the chipMinTouchTargetSize attribute.
You can find in the Chip source code:

if (shouldEnsureMinTouchTargetSize()) {
  setMinHeight(minTouchTargetSize);
}

You can change the chipMinTouchTargetSize in the layout or in the style:

    <com.google.android.material.chip.Chip
        app:chipMinTouchTargetSize="32dp"
        ../>

or you can set app:ensureMinTouchTargetSize="false".

enter image description here

Pay attention to change this value since it changes the minimum touch target size.

like image 113
Gabriele Mariotti Avatar answered Oct 21 '22 17:10

Gabriele Mariotti