Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView row styling - left aligned text, and right-aligned icon

I'm trying to get ListView row to look like the following:

| Text-Text-Text                        <ImageButton> |

With the imagebutton snapped to the right edge. How can I do this? Here's the current layout code I'm using. What am I doing wrong?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/layercontainer"
  android:orientation="horizontal"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:background="#699">
 <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:layout_gravity="left">
   <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="YO HOW SI IT GOESSDA" />
 </LinearLayout>

 <LinearLayout
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_weight="1"
   android:layout_gravity="right">
   <ImageButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/trash" />
 </LinearLayout>
</LinearLayout>

My code currently produces this: grrr

like image 935
Kleptine Avatar asked Feb 21 '10 22:02

Kleptine


1 Answers

Step #1: Use a RelativeLayout base.

Step #2: Put your ImageButton as having android:layout_alignParentRight="true"

Step #3: Put your TextView has having android:layout_alignParentLeft="true", android:layout_toLeftOf="..." (where ... is the ID of your ImageButton), and perhaps some other RelativeLayout.LayoutParams value for vertical alignment

like image 60
CommonsWare Avatar answered Nov 15 '22 08:11

CommonsWare