0

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>

Howli
  • 12,291
  • 19
  • 47
  • 72

1 Answers1

0

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>
Ram kiran Pachigolla
  • 20,897
  • 15
  • 57
  • 78
  • That works but only to an extent. If you put in the values "5th Class Rep Council", "Wed, March 13th - 5:30pm", "Auditorium", "AGM", "Tues, April 9th", "Auditorium" then Auditorium is wrapped onto a new line and the white border disappears again. – Howli Oct 05 '12 at 08:15
  • then don't use match_parent. just use weights to each textview inside your table row. so that they will align based on the weight you have given – Ram kiran Pachigolla Oct 05 '12 at 08:29
  • I'm sorry, but I don't follow? what weight? – Howli Oct 05 '12 at 22:46