Tôi cố gắng để gán độ rộng tương đối so với cột trong một ListView đó là trong một TabHost, sử dụng layout_weight như đề xuất here:vấn đề bố trí Android - độ rộng tương đối theo phần trăm sử dụng trọng lượng
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:id="@+id/triplist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="4px">
<TableRow>
<ListView android:id="@+id/triplistview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</TableRow>
<TableRow>
<Button android:id="@+id/newtripbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Trip"/>
</TableRow>
[other tabs ...]
định nghĩa hàng của tôi có 4 cột mà tôi muốn kích thước như sau:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1.0"
android:padding="4px">
<TextView android:id="@+id/rowtripdate"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:inputType="date"/>
<TextView android:id="@+id/rowodostart"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/rowodoend"
android:layout_weight=".2"
android:layout_width="0dip"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/rowcomment"
android:layout_weight=".4"
android:layout_width="0dip"
android:layout_height="wrap_content">
Thật không may, nó dường như muốn để phù hợp với tất cả các cột vào không gian mà các b utton chiếm, trái với chiều rộng của màn hình. Hoặc có thể có một ràng buộc khác mà tôi không hiểu. Tôi rất cảm kích sự giúp đỡ của bạn.
alt text http://heeroz.com/layoutprob.png
Tôi muốn thay đổi từ px để nhúng vào bố cục của bạn để hỗ trợ các độ phân giải màn hình khác nhau. –