我有一個自定義列表佈局。列表中的內容應該是,Android中的佈局處理
+--------------+-------------+------------+ |an image icon | text label |a checkbox | +--------------+-------------+------------+
- 圖像應始終左對齊
- 複選框應始終右對齊。
- 文本標籤應占用剩餘空間。
我的問題是,複選框沒有對齊到屏幕右側。它根據文本標籤的大小佔據該位置。 如果標籤太大,複選框從不顯示/一半顯示。
佈局文件示例如下
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TableLayout android:id="@+id/tableLayout1"
android:layout_width="match_parent" android:layout_height="wrap_content">
<TableRow android:id="@+id/tableRow1" android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:id="@+id/imageView1" android:src="@drawable/icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
<TableLayout android:id="@+id/tableLayout2"
android:layout_width="match_parent" android:layout_height="wrap_content">
<TableRow android:id="@+id/tableRow5" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:text="TextView" android:id="@+id/textView1"
android:layout_height="wrap_content"></TextView>
</TableRow>
<TableRow android:id="@+id/tableRow6" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:text="TextView" android:id="@+id/textView2"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</TableRow>
<TableRow android:id="@+id/tableRow7" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:text="TextView" android:id="@+id/textView3"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</TableRow>
<TableRow android:id="@+id/tableRow8" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:text="x"
android:id="@+id/textView4" android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</TableRow>
</TableLayout>
<CheckBox android:text="" android:id="@+id/checkBox1"
android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
</TableRow>
</TableLayout>
</LinearLayout>
這解決了我的問題。謝謝。 – Tyrant