2012-04-04 36 views
0

我有一個包含TableLayout的ScrollView。當一個AsyncTask完成爲我提取數據時,tablelayout以編程方式激活。然後,方法根據返回的數據量構建TableRows並將它們附加到TableLayout。Center Vert。 &Horiz。 TableLayout中的ProgressBar?

在XML中,TableLayout中的唯一項是ProgressBar。這裏的XML:

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/electionsScrollView" android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 


    <TableLayout android:id="@+id/electionsQuestionContainer" 
     android:layout_width="match_parent" android:layout_height="wrap_content"> 

     <ProgressBar android:id="@+id/electionsProgressBar" 
      style="?android:attr/progressBarStyleLarge" android:layout_width="wrap_content" 
      android:layout_height="match_parent" android:layout_gravity="center_vertical|center_horizontal" /> 

    </TableLayout> 
</ScrollView> 

我顯然不能把進度右側滾動視圖中,作爲滾動視圖只能承載一個項目(tablelayout)。我想我不希望將ProgressBar放置在表格行中,因爲我認爲這比移除progressBar.setVisibility(View.GONE);的AsyncTask會更麻煩。所以tableRow是我唯一的選擇,還是有一個原因,爲什麼我的ProgressBar不是在屏幕中間垂直和水平居中?

回答

0

我大約在那裏的一半。通過改變TableLayout的layout_gravity:

<TableLayout android:id="@+id/electionsQuestionContainer" 
    android:layout_width="match_parent" android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical|center_horizontal"> 

但是,這毀了我行編程方式添加外觀。有誰知道哪個Gravity.CONSTANT將使tableLayout返回默認值?當我沒有爲TableLayout的layout_gravity設置任何東西時,它看起來很完美。所以現在,我有ProgressDialog完全按照我喜歡的方式查看,但是行中填充的內容看起來不正確。怎麼了?頂部的表格距離屏幕的頂部大約一半(換句話說,我只能看到第一排桌子的一半,其餘的不在屏幕的頂部,不能滾動到達)。

我結束了使用兩個單獨的佈局,並刪除舊的。