【问题标题】:Align textview columns vertically when using custom adaptor / layoutinflator使用自定义适配器/layoutinflator 时垂直对齐 textview 列
【发布时间】:2012-04-05 22:16:31
【问题描述】:

我想垂直对齐三列。使用对象检索列的数据,然后使用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>

【问题讨论】:

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

标签: android textview alignment


【解决方案1】:

设置所有 textview 宽度和选项卡行宽度以填充父级并使用 layout_weight="1"。它会工作

【讨论】:

    【解决方案2】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-05
      • 2011-11-24
      • 1970-01-01
      • 2011-06-13
      • 1970-01-01
      • 2023-03-23
      相关资源
      最近更新 更多