Search code examples
androidandroid-tablelayout

Android table width queries


I have a table layout (code below), but I have am having a bit of a problem with the width of the cells. The picture below shows the problem. There should be a white border on the right hand side of the screen. I also want the text "Auditorium" not to wrap onto a new line (I would prefer that "13th -" get put onto the new line instead, I don't want to put \n in there because then it would mean it goes onto a new line at that point on bigger screens/landscape view).

How can I fix those two problems?

width problem

<?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>


Solution

  • just use this code in your xml file

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