SuperFrog
SuperFrog

Reputation: 7674

Android - align images in table Layout

I want to create a table row, which on the left are 3 images, and on the right a textview. Something You can usually see in a game (on the right the level number, and on the left the number of lives left.)

I have tried this layout, but one of the images isnt aligns to the right: (The table layout is nested within linear layout)

 <TableLayout
  xmlns:android="http://schemas.android.com/apk/res/android"   
  android:layout_width="fill_parent" 
  android:layout_height="100dp"
  android:shrinkColumns="0"  
  android:stretchColumns="1">
<TableRow        
     android:layout_width="fill_parent"         
     android:layout_height="fill_parent">   
  <ImageView  
     android:id="@+id/wa1"
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content" 
     android:layout_gravity="left"
     android:paddingRight="5px"
     android:paddingTop="6px"
     android:src="@drawable/v"/>
  <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"
      android:src="@drawable/v" 
      android:paddingTop="6px" 
      android:layout_gravity="left" 
      android:id="@+id/wa2" 
      android:paddingRight="5px">
  </ImageView>
  <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"
      android:src="@drawable/v" 
      android:paddingTop="6px" 
      android:layout_gravity="left" 
      android:id="@+id/wa3" 
      android:paddingRight="5px">
  </ImageView>
<TextView  
    android:id="@+id/question_status"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"
    android:gravity="right"
    android:textColor="#000000"
    android:textSize="26px"
    android:paddingLeft="125px"
    android:paddingRight="15px"
/>
</TableRow>

this is the relevant part of the result: enter image description here

10X alot :)

Upvotes: 0

Views: 9246

Answers (2)

Ben Williams
Ben Williams

Reputation: 6167

Assuming that </TableRow> is supposed to be followed by a </TableLayout>, try removing

android:shrinkColumns="0"  
android:stretchColumns="1"

from the TableLayout and

android:paddingLeft="125px"

from the TextView, to which instead you should add

android:layout_weight="1"

Upvotes: 4

Use android:layout_weight attribute on each column.

Upvotes: 0

Related Questions