Android的如何中心对齐芯片chipgroup?

问题描述 投票:10回答:6

我试过gravity="center"foregroundGravity="center"textAlignment="center"为ChipGroup XML文件中,但它不会工作。有任何想法吗?

android android-layout android-chips
6个回答
2
投票

我尝试使用芯片内部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>

enter image description here

应该有实现这个更好的方法,但这将在那里工作,我猜。


0
投票

这个库是帮助你找出你的查询。请it.and让我知道你对同样的想法。

该ChipCloud库最初是由fiskurgit一些较大的黑客马拉松项目(非常)很快敲了Android的看法。它创建材料“芯片”的包裹云。他们的版本基本的演示,请在Play商店的 - 我保持这个叉,因为我在它所需的功能。

Chip Cloud View


0
投票

把它放进一个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>

-1
投票

您可以通过创建一个父RelativeLayout的和每个chipgroup使用android:layout_centerHorizontal="true"去了,这样的事情

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true">

                <TextView
                    android:id="@+id/view1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="5dp"

                    android:background="@android:color/darker_gray"
                    android:text="View1" />

                <TextView
                    android:id="@+id/view2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="5dp"
                    android:layout_toRightOf="@id/view1"
                    android:background="@android:color/darker_gray"
                    android:text="View2" />
            </RelativeLayout>
        </RelativeLayout>

-2
投票

把芯片组的宽度成wrap_content和使父视图重力到center包含芯片组。因此,这将是定向的中心。


-4
投票

请尝试以下操作:

layout_gravity="center"

希望这会帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.