2014-01-17 53 views
0

我試圖讓Android ProgressBar水平地填充TableLayout中的剩餘空間。它的父行似乎佔據了整個寬度,但是當我將佈局參數設置爲match_parent時,沒有任何反應。我所得到的是相同的默認大小(48dip寬)ProgressBar。獲取Android ProgressBar以填充TableLayout行的其餘部分

我發現如果我只是把一個ProgressBar放在一個LinearLayout中,並將其設置爲match_parent,我就得到了我想要的。但不知何故,它在TableLayout中無法正常工作?

下面是相關的佈局代碼:

 <TableRow 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="X" /> 

      <ProgressBar 
       android:id="@+id/gyroConfX" 
       style="?android:attr/progressBarStyleHorizontal" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:indeterminate="false" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Y" /> 

      <ProgressBar 
       android:id="@+id/gyroConfY" 
       style="?android:attr/progressBarStyleHorizontal" 
       android:indeterminate="false" /> 
     </TableRow> 

     <TableRow 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Z" /> 

      <ProgressBar 
       android:id="@+id/gyroConfZ" 
       style="?android:attr/progressBarStyleHorizontal" 
       android:indeterminate="false" /> 
     </TableRow> 
    </TableLayout> 

下面是什麼樣子:

enter image description here

+0

嘗試使用「fill_parent」而不是「match_parent」。另外,你可以在你的進度條中加入: android:layout_width =「fill_parent」 android:layout_height =「wrap_content」 – SolArabehety

回答

1

嘗試增加layout_weight = 「1」 和layout_width = 「0dp」到進度條,像這樣:

<TableLayout 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"> 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Abcdefg" 
      /> 
     <ProgressBar 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      style="?android:attr/progressBarStyleHorizontal" 
      /> 
    </TableRow> 
    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     > 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Lorem Ipsum" 
      /> 
     <ProgressBar 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="wrap_content" 
      style="?android:attr/progressBarStyleHorizontal" 
      /> 
    </TableRow> 
</TableLayout>