我有一个ChipGroup和两个芯片在里面。我试图将marginTop添加到芯片中,但它们被堆放在ChipGroup的顶部。marginStart正在按预期工作,但marginTop什么也不做。

以下是我的xml:
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="match_parent"
android:layout_height="33dp"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.Chip
android:id="@+id/chip_1"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="92dp"
android:layout_height="25dp"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:text="Test"
app:chipCornerRadius="5dp"
app:chipMinTouchTargetSize="0dp"
app:closeIcon="@drawable/ic_close"
app:closeIconSize="10dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_2"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="92dp"
android:layout_height="25dp"
android:layout_marginStart="8dp"
android:layout_marginTop="5dp"
android:text="Test"
app:chipCornerRadius="5dp"
app:chipMinTouchTargetSize="0dp"
app:closeIcon="@drawable/ic_close"
app:closeIconSize="10dp" />
</com.google.android.material.chip.ChipGroup>发布于 2020-12-11 11:11:32
试试这个解决方案。

<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:paddingTop="@dimen/dp_15"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.Chip
android:id="@+id/chip_1"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="92dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="@dimen/dp_50"
android:text="Test"
app:chipCornerRadius="5dp"
app:chipMinTouchTargetSize="0dp"
app:closeIcon="@drawable/ic_close"
app:closeIconSize="10dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_2"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="92dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="@dimen/dp_5"
android:text="Test"
app:chipCornerRadius="5dp"
app:chipMinTouchTargetSize="0dp"
app:closeIcon="@drawable/ic_close"
app:closeIconSize="10dp" />
</com.google.android.material.chip.ChipGroup>https://stackoverflow.com/questions/65250025
复制相似问题