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

目前,到处都是列。我希望它们完美对齐。我正在使用TextView,但是我开始怀疑我是否应该使用某种TableLayout.


这是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>

最佳答案

android - 使用自定义适配器/layoutinflater时,垂直对齐textview列-LMLPHP尝试一下:

<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" />

关于android - 使用自定义适配器/layoutinflater时,垂直对齐textview列,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9803879/

10-14 16:23
查看更多