首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android如何在芯片组中对齐芯片?

Android如何在芯片组中对齐芯片?
EN

Stack Overflow用户
提问于 2018-07-05 20:56:11
回答 8查看 13.7K关注 0票数 38

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

EN

回答 8

Stack Overflow用户

回答已采纳

发布于 2018-08-16 22:13:46

我试着在Flexbox中使用芯片,它是这样工作的。

代码语言:javascript
复制
<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,以编程方式填充它。

票数 23
EN

Stack Overflow用户

发布于 2019-06-10 15:14:47

把它放入一个LinearLayout,并使它的重力"center_horizontal“。然后将芯片组的layout_width设置为"wrap_content“。这对我有用。

代码语言:javascript
复制
    <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>
票数 5
EN

Stack Overflow用户

发布于 2021-05-28 03:24:33

如果您的ChipGroupConstraintLayout中,请使用

代码语言:javascript
复制
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"

因此:

代码语言:javascript
复制
<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,因为它不会那样工作。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51199787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档