我在XML文件中尝试了gravity="center"、foregroundGravity="center"和textAlignment="center"的ChipGroup,但是它无法工作。有什么想法吗?

发布于 2018-08-16 22:13:46
我试着在Flexbox中使用芯片,它是这样工作的。
<com.google.android.flexbox.FlexboxLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
app:flexWrap="wrap"
app:justifyContent="center"> ... </com.google.android.flexbox.FlexboxLayout>

应该有更好的方法来实现这一点,但这将在那里工作,我想。
Update (2021年):由于Google的稳定性和缺乏更新,我消除了对flexbox的依赖,现在使用ConstraintLayout的流程实现了同样的效果,任何使用这种技术的人都可以考虑这一点,看看https://stackoverflow.com/a/61545990,以编程方式填充它。
发布于 2019-06-10 15:14:47
把它放入一个LinearLayout,并使它的重力"center_horizontal“。然后将芯片组的layout_width设置为"wrap_content“。这对我有用。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center_horizontal">
<com.google.android.material.chip.ChipGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/langsChipGroup"
>
</com.google.android.material.chip.ChipGroup>
</LinearLayout>发布于 2021-05-28 03:24:33
如果您的ChipGroup在ConstraintLayout中,请使用
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"因此:
<com.google.android.material.chip.ChipGroup
android:id="@+id/chips"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
...确保不要将layout_width字段设置为match_parent,因为它不会那样工作。
https://stackoverflow.com/questions/51199787
复制相似问题