Luke Batley Luke Batley - 17 days ago 6
Android Question

Spacing views evenly across multiple screen sizes

I'm trying to create a league table but I am struggling to align things evenly if the number goes into double figures it pushes the next one on also on different phones the table is completely out of line etc. so does any one know how I can align views evenly and center the numbers so that it doesn't knock everything out of sync.

Ideally I want it to like this:

8 team 2 5 3 10 0 8 0
9 team 2 5 3 10 0 8 0
10 team 2 5 3 10 0 8 0
11 team 2 5 3 10 0 8 0


currently its doing this

8 team 2 5 3 10 0 8 0
9 team 2 5 3 10 0 8 0
10 team 2 5 3 10 15 8 0
11 team 2 5 3 10 0 8 0


Here's my layout:

<?xml version="1.0" encoding="utf-8"?>

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="20dip"
android:background="@drawable/bg_tablecell"
android:orientation="horizontal"
>
<TableRow>
<TextView
android:id="@+id/position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dip"
android:text="@string/POS"
android:textSize="15dip"
android:textColor="@color/blue"
android:gravity="center"
/>

<TextView
android:id="@+id/TeamName"
android:layout_width="90dip"
android:layout_height="wrap_content"
android:layout_marginLeft="23dip"
android:ellipsize="end"
android:gravity="left"
android:lines="1"
android:text="@string/Team"
android:textColor="@color/blue"
android:textSize="15dip"
android:textStyle="bold"
/>

<TextView
android:id="@+id/played"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:gravity="center"
android:text="@string/Zero"
android:textColor="@color/blue"
android:textSize="15dip"
/>

<TextView
android:id="@+id/won"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:gravity="center"
android:text="@string/Zero"
android:textColor="@color/blue"
android:textSize="15dip"
/>

<TextView
android:id="@+id/drawn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:gravity="center"
android:text="@string/Zero"
android:textColor="@color/blue"
android:textSize="15dip"
/>

<TextView
android:id="@+id/lost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:gravity="center"
android:text="@string/Zero"
android:textColor="@color/blue"
android:textSize="15dip"
/>

<TextView
android:id="@+id/goalsFor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:gravity="center"
android:text="@string/Zero"
android:textColor="@color/blue"
android:textSize="15dip"
/>

<TextView
android:id="@+id/goalsAgainst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:gravity="center"
android:text="@string/Zero"
android:textColor="@color/blue"
android:textSize="15dip"
/>

<TextView
android:id="@+id/Difference"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:gravity="center"
android:text="@string/Zero"
android:textColor="@color/blue"
android:textSize="15dip"
/>

<TextView
android:id="@+id/points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="13dp"
android:gravity="center"
android:text="@string/Zero"
android:textColor="@color/blue"
android:textSize="15dip"
/>
</TableRow>
</TableLayout>

Answer

I have Added Six Coloumn You can Add Coloumn accordin to your need

you just have to set the android:width to measure same of all coolumns

My code is

 <?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/lv"
android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"
android:textColor="#000000">
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
        android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#ffffff">
        <TextView android:id="@+id/t1"   android:textColor="#7E3517" android:typeface="sans"
        android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
        android:layout_weight="1.0" android:width="10dip" android:gravity="left"/>
        <TextView android:id="@+id/t2"   android:textColor="#7E3517" android:typeface="sans"
        android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
        android:layout_weight="1.0" android:width="10dip" android:gravity="right"/>
        <TextView android:id="@+id/t3"   android:textColor="#7E3517" android:typeface="sans"
        android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
        android:layout_weight="1.0" android:width="10dip" android:gravity="left"/>
        <TextView android:id="@+id/t4"   android:textColor="#7E3517" android:typeface="sans"
        android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
        android:layout_weight="1.0" android:width="10dip" android:gravity="right"/>
        <TextView android:id="@+id/t5"   android:textColor="#7E3517" android:typeface="sans"
        android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
        android:layout_weight="1.0" android:width="10dip" android:gravity="left"/>
        <TextView android:id="@+id/t6"   android:textColor="#7E3517" android:typeface="sans"
        android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
        android:layout_weight="1.0" android:width="10dip" android:gravity="right"/>
        <TextView android:id="@+id/t7"   android:textColor="#7E3517" android:typeface="sans"
        android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
        android:layout_weight="1.0" android:width="10dip" android:gravity="left"/>
        <TextView android:id="@+id/t8"   android:textColor="#7E3517" android:typeface="sans"
        android:textSize="14sp" android:layout_height="fill_parent" android:layout_width="wrap_content"
        android:layout_weight="1.0" android:width="10dip" android:gravity="right"/>

    </LinearLayout>
</LinearLayout>
Comments