android, cannot align icons on the right in listview's row
I am currently working on my first android app. In a listview, I need to have the following organisation in each row:
- On the left: one main icon on which takes the whole height of the row
- On the middle: 2 texts, one below the other
- On the right: 2 icons, one below the other
I end up with a row.xml file like this, but that does not work as I expect. Do you know if something obvious is missing in this file ? Thanks a lot, Luc
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/icon"
android:layout_width="48px"
android:layout_height="48px"
android:layout_marginRight="0dip"
android:src="@drawable/icon" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="0dp"
and开发者_开发知识库roid:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="16dp"
android:textStyle="bold"
android:text="TITLE"
android:paddingLeft="5dp"
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="14dp"
android:text="DESCRIPTION"
android:paddingLeft="5dp"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="right">
<ImageButton
android:id="@+id/button_modify"
android:layout_width="16px"
android:layout_height="16px"
android:src="@drawable/deleteicon"
/>
<ImageButton
android:id="@+id/button_delete"
android:layout_width="16px"
android:layout_height="16px"
android:src="@drawable/modifyicon"
/>
</LinearLayout>
In the right-hand-column LinearLayout
, add
android:layout_width="wrap_content"
android:gravity="right"
That should make the icons should fall to the right (because of the gravity
setting.)
Consider switching to RelativeLayout
for a rule set like you describe. Using LinearLayouts
may not work in all cases and will be less efficient than the RelativeLayout
in terms of stack consumption.
精彩评论