[英]How to arrange the chip in second row when the first row is filled in linear layout horizontal?
[英]Chip Group Second Row Overlaps
現在我有一個有 4 個芯片的芯片組,它的布局尺寸正確(意味着它沒有獲得整個屏幕寬度),當第四個芯片中的文本變得太長時,它會將其移動到下一行. 我添加了這段代碼:
app:chipMinTouchTargetSize="0dp"
讓芯片之間的空間更小,因為以前空間真的很大,但現在空間太小了。 填充或邊距也不起作用,但我可能做錯了什么。
<LinearLayout
android:layout_width="312dp"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginStart="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/line2">
<com.google.android.material.chip.ChipGroup
android:layout_width="300dp"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/line2"
android:layout_height="match_parent">
<com.google.android.material.chip.Chip
android:id="@+id/tag1"
style="@style/Colors_Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="Tag1"
android:textSize="11sp"
app:chipMinTouchTargetSize="0dp" />
<com.google.android.material.chip.Chip
android:id="@+id/tag2"
style="@style/Colors_Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="Tag2"
android:textSize="11sp"
app:chipMinTouchTargetSize="0dp" />
<com.google.android.material.chip.Chip
android:id="@+id/tag3"
style="@style/Colors_Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:text="Tag3"
android:textSize="11sp"
app:chipMinTouchTargetSize="0dp" />
<com.google.android.material.chip.Chip
android:id="@+id/tag4"
style="@style/Colors_Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="Tag4"
android:textSize="11sp"
app:chipMinTouchTargetSize="0dp" />
</com.google.android.material.chip.ChipGroup>
</LinearLayout>
</LinearLayout>
問題是我制作了一個單獨的樣式組件來設計芯片。 我沒有在布局文件中包含chipMinTouchTargetSize
,而是將其包含在樣式部分中。 然后我將app:chipSpacingVertical="5dp"
添加到芯片組父級。 它奏效了。
風格:
<style name="Colors_Widget.MaterialComponents.Chip.Choice" parent="Widget.MaterialComponents.Chip.Choice">
<item name="chipCornerRadius">12dp</item>
<item name="chipMinHeight">24dp</item>
<item name="chipMinTouchTargetSize">5dp</item>
<item name="chipBackgroundColor">@color/honeyBright</item>
<item name="android:textColor">@color/black</item>
</style>
布局
<com.google.android.material.chip.ChipGroup
android:layout_width="300dp"
android:layout_marginBottom="0dp"
app:chipSpacingVertical="5dp"
app:layout_constraintBottom_toTopOf="@+id/line2"
android:layout_height="match_parent">
<com.google.android.material.chip.Chip
android:id="@+id/tag1"
style="@style/Colors_Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tag1"
android:textSize="11sp" />
</com.google.android.material.chip.ChipGroup>
這是現在的樣子:正確的芯片組圖像
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.