TableLayout与图标对齐

时间:2012-08-26 17:12:10

标签: android icons alignment tablelayout

这是我的XML。 我想将图标对齐到左边,文本应该出现在图标旁边,有一些空格,就像你在其他地方看到的那样。但是文本出现在中心。 (或右对齐第二列,两列布局)

 <?xml version="1.0" encoding="utf-8"?>
  <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/main_scroll"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fillViewport="true" >

  <TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="@android:color/white"
    android:layout_margin="5dp"
    android:stretchColumns="2"  
    android:layout_height="wrap_content">

       <TableRow
        android:id="@+id/events_header"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@android:drawable/list_selector_background"
        android:clickable="true"
        android:padding="5dip">
              <ImageView android:id="@+id/ImageView02" 
                  android:src="@drawable/event_icon"
                      android:layout_width="wrap_content"
          android:layout_height="wrap_content"
                  android:layout_gravity="center_vertical|left"
                  android:layout_margin="5dp">
              </ImageView>
              <TextView
                android:id="@+id/text1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="View Events"
                android:layout_gravity="left"
                android:textSize="21dp"
                android:textStyle="bold"
                android:background="@android:color/black"
                android:textColor="@android:color/white" />
         </TableRow>
        </TableLayout>
   </ScrollView>

它的显示方式如下:

    [  *             View Events        ]
  • 是图标。我想这样显示。

    [  *  View Events                   ]
    

1 个答案:

答案 0 :(得分:0)

尝试将android:stretchColumns="2"更改为android:stretchColumns="1",因为列索引以 0 开头。因此,如果您只有两列,则第二列代表索引 1

相关问题