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>