2011-12-05 21 views
1

我正在研究一個應用程序,其中包含滾動視圖中的表格佈局。 我想要表格填充屏幕的寬度,但我現在不真的該怎麼做。 我試着先將scrollView設置爲fill_parent,但後來我得到了數十個「未處理的事件循環異常」。還有大約三個「無效的首選項頁面路徑:XML語法」錯誤。 如果我只是試圖設置表格佈局fill_parent只是沒有任何反應。 這裏是我的「上滾動表建設」帶有滾動視圖的Android表格佈局不適合父母寬度

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

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <Button 
     android:id="@+id/btnNew" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.20" 
     android:text="New" /> 

    <Button 
     android:id="@+id/btnDelete" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.20" 
     android:text="Delete" /> 
</LinearLayout> 


<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_weight="0.20" > 

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

     <TableRow 
      android:id="@+id/tableRow1" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 

      <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@drawable/cell_shape2" 
       android:padding="5dp" 
       android:textAppearance="?android:attr/textAppearanceSmall" /> 

...等(沒有必要太多的東西)的exerpt。

我希望你能給我一個提示,因爲我真的不知道爲什麼我的scrollview不適合父寬度,我不知道,如果它會幫助,如果它適合。 在此先感謝。

回答

7

如果您使用的是Eclipse,請嘗試使用菜單Project - > Clean ... - >(選擇您的項目) - >按OK。有時需要在您更改某些內容時重新編譯xml資源。

此外,我不認爲你可以在XML佈局的根目錄中同時具有LinearLayout和ScrollView。

如果您想內容來填充你的列可能需要設置

android:stretchColumns="1" 

在TableLayout和

android:layout_column="1" 

在TextView的。

您也可以嘗試和了滾動使用

android:fillViewport="true" 

+0

好的,謝謝,錯誤消失了,但是如果我將兩個元素都設置爲match_parent,表格仍然與列中的文本一樣大。 – mkay

+0

請發佈您的所有xml。 –

+0

XML大約有1700行......你確定?它是一個非常大的桌子... – mkay

相關問題