gpt4 book ai didi

Android表格行,不能居中文本

转载 作者:行者123 更新时间:2023-11-29 20:55:34 26 4
gpt4 key购买 nike

我有以下布局代码:

<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableLayout1"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<!-- APP NAME -->
<TableRow
android:id="@+id/table_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#2d9adf"
android:gravity="center_vertical"
android:padding="5dip" >

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

<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center_horizontal"
android:text="@string/app_name"
android:textColor="#fff"
android:textSize="16sp" />

</RelativeLayout>
</TableRow>

问题是,结果没有居中(见下图):

enter image description here

请问如何解决?

最佳答案

很容易解决这个问题。您需要更改 RelativeLayout 以具有正确的尺寸:

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

这样它会拉伸(stretch)顶部 TableRow 的完整大小。然后你可以将它添加到你的TextView:

android:layout_centerInParent="true"

使 TextViewRelativeLayout 中居中,它跨越 TableRow

关于Android表格行,不能居中文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27890740/

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