【问题标题】:Android Material Chip Margin Top does nothingAndroid Material Chip Margin Top 什么都不做
【发布时间】:2020-12-11 10:57:07
【问题描述】:

我有一个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>

【问题讨论】:

  • 为什么不给chipgroup设置margin呢?
  • @Bhavnik 因为这会移动整个芯片组。我只希望芯片在芯片组中具有顶部边缘,而不是堆叠在其顶部

标签: android android-layout android-chips


【解决方案1】:

试试这个解决方案。

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

【讨论】:

  • 在芯片组中填充顶部是解决方案谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-06-23
  • 2021-11-19
  • 2020-05-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-14
相关资源
最近更新 更多