我正在嘗試使用每行的文本和圖像進行listview。 圖像應該在右邊,文字應該包含行的其餘部分。文本應該以垂直爲中心。 我可以做所有這些,除了居中的部分。 這是我經過多次失敗的嘗試:在列表視圖行上垂直居中文本
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget71"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center_vertical">
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginTop="6px"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@+id/text1"
android:layout_weight="01"
android:layout_gravity="center_vertical|fill_vertical|center_horizontal|center|clip_vertical"/>
<ImageView
android:id="@android:id/icon"
android:layout_width="30px"
android:layout_height="40px"
android:layout_marginTop="8px"
android:layout_marginLeft="4px"
android:layout_marginRight="8px"
android:src="@drawable/delete"
android:layout_gravity="right" />
</LinearLayout>
無論什麼文本對百達行的頂部。 我已經看到一些報告,這可能會發生,因爲手動完成xml充氣的方式。但我不這樣做。我把它留給框架。
最後它工作了! 你的答案就是這樣。雖然我也用piotrpo答案(可以接受兩者?)。 – Nahoot 2012-02-21 19:18:19