2010-05-26 26 views
13

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

Trả lời

11

Tôi nghĩ rằng tôi đã quên tài sản này cho các phần tử TableLayout:

android:stretchColumns="0" 

Nó dường như được làm việc ngay bây giờ.

+7

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. –

1

Tôi không thấy bất cứ điều gì rõ ràng là sai về những gì bạn đang hiển thị ở đó. Để có được hình ảnh tốt hơn về những gì đang diễn ra, bạn có thể thử dùng số heirarchy viewer. Nó đi kèm với SDK. Nó sẽ hình dung cho bạn bao nhiêu không gian mỗi lớp "ẩn" đang dùng, vì vậy bạn có thể tìm ra cái nào đã quyết định chỉ lớn như vậy.

+0

Cảm ơn gợi ý. Tôi đã không biết công cụ này. Tôi thấy rằng ListView (136px) không lấp đầy toàn bộ chiều rộng của hàng bảng (480px), nhưng tại sao lại là một câu hỏi khác. 136px cũng xảy ra với chiều rộng của nút. – cdonner

Các vấn đề liên quan