Here is my XML.
I want to align the icon to the left and the text should appear right next to the icon, with some space, like you see elsewhere. But the text is showing up in the center. (or right aligned to the 2nd column, in two column layout)
<?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>
This is how it displays:
[ * View Events ]
-
is the icon. I want to display like this.
[ * View Events ]
Try changing
android:stretchColumns="2"toandroid:stretchColumns="1"because column index starts with 0. So if you only have two columns then the second column stands at index 1.