0

或者我將不得不將ScrollView合併到TableLayout中?這甚至有可能嗎?我想爲屏幕動態創建任意數量的行,但需要將行滾動。TableLayout是否會提供一個垂直滾動條?

我一直在努力嘗試使用LinearLayout工作太久,並認爲是時候移動到TableLayout或RelativeLayout - 關於一個優先級的任何意見?

回答

2

沒有了「列表「式的視圖會自動滾動。 LinearLayout,TableLayout,RelativeLayout,他們都沒有這樣做,因爲(像其他人指出的)將它們包裝在ScrollView中非常簡單,它只是它們不需要的功能。

+0

好吧,謝謝;我將發佈我的理論佈局,看看是否有人對此發表評論。 – 2012-03-13 13:28:43

4

你可以在滾動佈局中使用表格佈局,這是可能的。 例如,

<ScrollView 
      xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical" > 

      <LinearLayout 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 
</LinearLayout> 

</ScrollView> 

您可以使用表格佈局,而不是線性佈局..

+0

是的,我知道我可以使用TableLayout;我的問題是,當屏幕上顯示的行太多時,TableLayout會添加一個垂直滾動條嗎? – 2012-03-13 05:03:43

+0

@黏土香農:是的,它會工作......只是試試看......如果它不,那麼讓我知道...... – 2012-03-13 05:05:53

1

你必須指定你TableLayout就像低於ScrollView

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:background="#ffffff" 
    android:layout_height="fill_parent"> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:background="#ffffff"> 

     <TableLayout 
      android:id="@+id/myTableLayout" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center" 
      android:shrinkColumns="1"/>  

    </RelativeLayout> 

</ScrollView>