0

我有一个表格布局(下面的代码),但是单元格的宽度有点问题。下图显示了问题。屏幕右侧应该有一个白色边框。我还希望文本“Auditorium”不要换行(我希望将“13th -”放到新行上,我不想把 \n 放在那里,因为这样就意味着它会继续在更大的屏幕/横向视图的那个点上换行)。

我该如何解决这两个问题?

宽度问题

<?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="#013567" >

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="*"
    android:stretchColumns="*" >

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textlines"
            android:gravity="center"
            android:text="@string/meeting_5"
            android:textColor="#fff" >
        </TextView>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textlines"
            android:gravity="center"
            android:text="@string/meeting_5_date"
            android:textColor="#fff" >
        </TextView>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textlines"
            android:gravity="center"
            android:text="@string/meeting_5_location"
            android:textColor="#fff" >
        </TextView>
    </TableRow>

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textlines"
            android:gravity="center"
            android:text="@string/AGM"
            android:textColor="#fff" >
        </TextView>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textlines"
            android:gravity="center"
            android:text="@string/AGM_date"
            android:textColor="#fff" >
        </TextView>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/textlines"
            android:gravity="center"
            android:text="@string/AGM_location"
            android:textColor="#fff" >
        </TextView>
    </TableRow>
</TableLayout>

4

1 回答 1

0

只需在您的 xml 文件中使用此代码

  <TableLayout
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:shrinkColumns="*"
     android:stretchColumns="*" 
     android:layout_margin="2dp"
     android:layout_gravity="center_horizontal">

<TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:text="meeting_5"
        android:textColor="#fff" >
    </TextView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:text="meeting_5_date"
        android:textColor="#fff" >
    </TextView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:text="meeting_5_location"
        android:textColor="#fff" >
    </TextView>
</TableRow>

<TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:text="AGM"
        android:textColor="#fff" >
    </TextView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:text="AGM_date"
        android:textColor="#fff" >
    </TextView>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/textlines"
        android:gravity="center"
        android:text="AGM_location"
        android:textColor="#fff" >
    </TextView>
</TableRow>
</TableLayout>
</ScrollView>
于 2012-10-05T03:36:22.547 回答