gpt4 book ai didi

Android如何将固定大小的芯片文本居中?

转载 作者:行者123 更新时间:2023-11-29 16:29:03 24 4
gpt4 key购买 nike

我有一个宽度为 100dp 的纸条,但文本没有居中,我该如何使文本居中。

我将 androidx 与 Material 库一起使用,我试过放置 android:textAlignment="center"android:gravity="center" 但不起作用

<com.google.android.material.chip.Chip
android:id="@+id/chip"
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="7:00" />

我有这个

chip

我要这个

enter image description here

最佳答案

刚才我遇到了同样的问题,通过设置芯片属性解决了:android:textAlignment = "center"。我测试了你的例子,它也工作正常,这里是我测试的代码:

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.chip.Chip
android:id="@+id/chip"
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="7:00"
android:textAlignment="center"/>
</FrameLayout>

还要确保您没有在代码中的某处设置或更改纸条的文本对齐方式。

关于Android如何将固定大小的芯片文本居中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57730951/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com