2011-04-24 40 views
0

我想创建一个表格行,左边是3张图片,右边是textview。 东西你通常可以在游戏中看到(在右边的水平数字,在左边的剩余生命数)。Android - 对齐表格中的图像布局

我试过这种布局,但其中一个图像没有对齐到右侧:(表布局嵌套线性布局内)

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

这是结果的相关部分: enter image description here

10X很多:)

回答

3

假设由</TableLayout></TableRow>应该遵循,尝试删除

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

android:paddingLeft="125px" 

从TextView的,哪个不是你应该增加

android:layout_weight="1" 
+0

这就是完美:) – 2011-04-24 17:05:03

+0

你能解释一下你改变了什么来解决它吗? – 2011-04-24 17:05:28

+0

shrink和stretchColumns不是标志,它们是可缩放/可伸缩的列的列表,所以你的xml实际上做了什么,“让第二个ImageView填充所有可用空间”; stretchColumns =“3”也可以解决你的问题。 – 2011-04-24 17:30:35

0

在每列上使用android:layout_weight属性。

+0

10x。我曾尝试添加android:layout_weight,但它没有改变布局。 – 2011-04-24 16:35:12