Android 使用自定义适配器/布局器时,垂直对齐textview列

Android 使用自定义适配器/布局器时,垂直对齐textview列,android,textview,alignment,Android,Textview,Alignment,我有三列要垂直对齐。列的数据使用对象检索,然后使用LayoutInflater显示。 现在到处都是柱子。我希望它们能完全对齐。我正在使用TextView,但我开始怀疑我是否不应该使用某种表格布局。 以下是XML: <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/t

我有三列要垂直对齐。列的数据使用对象检索,然后使用
LayoutInflater显示。

现在到处都是柱子。我希望它们能完全对齐。我正在使用
TextView
,但我开始怀疑我是否不应该使用某种
表格布局。

以下是XML:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/table_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <ListView
        android:id="@android:id/list"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <TableRow android:id="@+id/row_multi_row">

        <TextView
            android:id="@+id/item1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="3dip"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/item2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="3dip"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <TextView
            android:id="@+id/item3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:padding="3dip"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </TableRow>
</TableLayout>

设置所有文本视图宽度和选项卡行宽度以填充父级并使用布局\u weight=“1”。它将工作

设置所有文本视图宽度和选项卡行宽度以填充父级并使用布局_weight=“1”。它将起作用

尝试以下方法:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_multi_row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">

<TextView
    android:id="@+id/item1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.34"
    android:padding="3dip"
    android:text="asdasd"
    android:gravity="center"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/item2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.34"
    android:padding="3dip"
    android:gravity="center"
    android:text="adasd"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/item3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.32"
    android:padding="3dip"
    android:gravity="center"
    android:text="asdasdad"
    android:textAppearance="?android:attr/textAppearanceLarge" />

试试这个:

<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_multi_row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">

<TextView
    android:id="@+id/item1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.34"
    android:padding="3dip"
    android:text="asdasd"
    android:gravity="center"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/item2"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.34"
    android:padding="3dip"
    android:gravity="center"
    android:text="adasd"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/item3"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.32"
    android:padding="3dip"
    android:gravity="center"
    android:text="asdasdad"
    android:textAppearance="?android:attr/textAppearanceLarge" />


您的文本视图未设置为
填充父视图
,因此它们只会占用所需的空间。您的文本视图未设置为
填充父视图
,因此它们只会占用所需的空间。