Reputation: 2381
I have a custom listview with this layout xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<TableRow android:gravity="center" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="left"/>
<TextView
android:id="@+id/headline"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:gravity="center"/>
</TableRow>
</TableLayout>
it works fine but i want the imagebutton to be aligned at left and textview aligned at center.
Searching a lot i find that using gravity on tablerow i can align the tablerow content, but imageview gravity and textview gravity seems to have no effect
that layout make it look like
[ Image text ]
i want it look like
[Image text ]
So image aligned left and textview centered, but i dont want to use fixed separation because the text its dynamically loaded and i cant know its lenght
Can someone help me?
Sorry for my bad english
Upvotes: 0
Views: 113
Reputation: 9035
Use this xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout
android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<TableRow >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:gravity="left"
android:src="@drawable/ic_launcher"/>
<TextView
android:id="@+id/headline"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center|center_horizontal"
android:gravity="center"
android:text="Text"/>
</TableRow>
</TableLayout>
</LinearLayout>
Upvotes: 1