2012-02-27 18 views
1

我是一名新手Android程序員,並且我已被分配來創建一個活動,該活動顯示按版本對應用進行的更改的表。該表有四列,即Id,Type,Description和Version。TableRow中的列使用權重和權重進行劃分不能正確間隔元素

爲此,我在TableView中放置了一個TableLayout。然後,我有一個TableRows模板,在運行時動態膨脹。列寬應保持不變;他們可以溢出高度但不是寬度。

爲了達到這個目的,我嘗試了分別使用weight和row容器的總和屬性&。 (我已經將layout_width設置爲零)。

問題是,列擴展到屏幕邊界之外。我會張貼圖像,但我沒有權力。

(風景看起來很近,但你可以看到外邊界仍然被切斷)。

我注意到,如果孩子的體重增加到總體的45%左右,那麼權重就接近了。

最後,分隔列的視圖被賦予了0和1dip寬度的權重。 (我不確定這是否會導致問題)。

有什麼建議嗎?

對我來說,看起來像加權使用的寬度就好像它在橫向模式。我必須做兩個佈局,一個是肖像,一個是風景?

我已經添加了XML佈局表格行:

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/table_row_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <View 
      android:id="@+id/top_border" 
      android:layout_width="match_parent" 
      android:layout_height="1dip" 
      android:background="#FFFFFF" /> 

     <LinearLayout 
      android:id="@+id/horizontal_container" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="4" > 

      <View 
       android:id="@+id/view1" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_id" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Id" android:textSize="10sp" android:layout_weight="0.5"/> 

      <View 
       android:id="@+id/view2" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_type" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Type" android:textSize="10sp" android:layout_weight="1"/> 

      <View 
       android:id="@+id/view3" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_desc" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Description" android:textSize="10sp" android:layout_weight="2"/> 

      <View 
       android:id="@+id/view4" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_version" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Version" android:textSize="10sp" android:layout_weight="0.5"/> 

      <View 
       android:id="@+id/view6" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 
     </LinearLayout> 

     <View 
      android:id="@+id/view7" 
      android:layout_width="match_parent" 
      android:layout_height="1dip" android:background="#FFFFFF"/> 

    </LinearLayout> 

</TableRow> 

上下觀點是頂部和底部邊框。

這裏是它獲取添加過表的佈局:

<?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="fill_parent" 
    android:orientation="vertical" android:scrollbarAlwaysDrawVerticalTrack="true"> 

    <ScrollView 
     android:id="@+id/view_scroll" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" android:fillViewport="true"> 

     <TableLayout 
      android:id="@+id/table_layout" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:shrinkColumns="0" 
      android:stretchColumns="0" > 
     </TableLayout> 

    </ScrollView> 

</LinearLayout> 
+1

你能參考添加一行佈局?另外,如果各個權重的總和不超過['android:weightSum'](http://developer.android.com/reference/android/widget/LinearLayout)中指定的值,我再次檢查一遍。 html#attr_android:weightSum)(我假設你在提到這個屬性時犯了一個錯字)。 – 2012-02-27 05:20:30

回答

1

由於MH。

對不起,不能早點回復你。 (我是新來的Android和堆棧溢出...我沒有意識到你回答了我的任務。)我添加了行佈局。

<?xml version="1.0" encoding="utf-8"?> 
<TableRow xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <LinearLayout 
     android:id="@+id/table_row_container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <View 
      android:id="@+id/top_border" 
      android:layout_width="match_parent" 
      android:layout_height="1dip" 
      android:background="#FFFFFF" /> 

     <LinearLayout 
      android:id="@+id/horizontal_container" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:weightSum="4" > 

      <View 
       android:id="@+id/view1" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_id" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Id" android:textSize="10sp"  android:layout_weight="0.20"/> 

      <View 
       android:id="@+id/view2" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_type" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Type" android:textSize="10sp" android:layout_weight="0.5"/> 

      <View 
       android:id="@+id/view3" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_desc" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Description" android:textSize="10sp" android:layout_weight="1"/> 

      <View 
       android:id="@+id/view4" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 

      <TextView 
       android:id="@+id/txt_version" 
       android:layout_width="0dip" 
       android:layout_height="wrap_content" 
       android:text="Version" android:textSize="10sp" android:layout_weight="0.25"/> 

      <View 
       android:id="@+id/view6" 
       android:layout_width="1dip" 
       android:layout_height="match_parent" 
       android:background="#FFFFFF" android:layout_weight="0.01"/> 
     </LinearLayout> 

     <View 
      android:id="@+id/view7" 
      android:layout_width="match_parent" 
      android:layout_height="1dip" android:background="#FFFFFF"/> 

    </LinearLayout> 

</TableRow> 

大衛