gpt4 book ai didi

Android:根据按钮文本对齐文本

转载 作者:太空狗 更新时间:2023-10-29 14:18:09 27 4
gpt4 key购买 nike

我有一个 RelativeLayout,其中有一个按钮,下面是一个文本。我想根据按钮文本对齐文本,即它从左侧开始的宽度与按钮文本的宽度相同。

我尝试使用 android:layout_alignLeft="@id/myButton" 但这会将其对齐到按钮的边缘,而不是按钮文本的边缘。

有什么办法可以实现吗?

在我的布局 XML 中,按钮和文本如下所示:

<Button
android:id="@+id/myButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:text="Some text" />

<TextView
android:id="@+id/myTextView"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignLeft="@id/myButton"
android:layout_below="@id/myButton"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:text="Some text"
android:textAppearance="?android:attr/textAppearanceMedium" />

最佳答案

请在您的 TextView 内容中使用此字段 android:gravity="center"。你会得到相同的..它工作正常..请使用这个

关于Android:根据按钮文本对齐文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19451754/

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