表格布局包装文本android

时间:2014-05-26 09:50:53

标签: android

我正在创建动态表。第一行是静态的。

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

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/DarkGray" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/Black"
            android:background="@drawable/cell_shape"
            android:text="Аватар"
            android:textSize="16dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/Black"
            android:background="@drawable/cell_shape"
            android:text="Выезд"
            android:textSize="16dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/cell_shape"
            android:text="Откуда"
            android:textColor="@color/Black"
            android:textSize="16dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/cell_shape"
            android:text="Куда"
            android:textColor="@color/Black"
            android:textSize="16dp"
            android:textStyle="bold" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/Black"
            android:background="@drawable/cell_shape"
            android:text="М/Ц"
            android:textSize="16dp"
            android:textStyle="bold" />
    </TableRow>

</TableLayout>
</ScrollView>

第二行和其他行是动态的,它们以编程方式填充

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableRow1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#DEDEDE" >
    <ImageView
        android:id="@+id/imageStatus"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/cell_shape" />

    <TextView
        android:id="@+id/textVuezd"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/cell_shape"
        android:text=""
        android:textColor="@color/Black"
        android:textSize="12dp" />

    <TextView
        android:id="@+id/textOtkuda"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/cell_shape"
        android:text=""
        android:textColor="@color/Black"
        android:textSize="12dp" />

    <TextView
        android:id="@+id/textKuda"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/cell_shape"
        android:text=""
        android:textColor="@color/Black"
        android:textSize="12dp" />

    <TextView
        android:id="@+id/textSeatsPrice"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/cell_shape"
        android:text=""
        android:textColor="@color/Black"
        android:textSize="12dp" />

</TableRow>

我将此表显示为对话框,并得到了这个:

http://www.autostarkiev.com.ua/gg.png

由于字体大小我只能看到整个表的一半。如何在文本视图换行中创建文本,以便我可以看到整个表格?

1 个答案:

答案 0 :(得分:13)

对于TextView中的每个TableRow,将0dp替换为“match_parent”并改为使用权重。

更改行:

android:layout_width="match_parent"

至行:

android:layout_width="0dp"
android:layout_weight="1"

如果您希望列比其他列更大,只需将权重从1更改为更大的数字。

相关问题