如何制作可滚动的TableLayout?

iTu*_*rki 51 android scroll android-tablelayout

请看这里的XML代码:

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    xmlns:android="http://schemas.android.com/apk/res/android">

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

    <!-- Some stuff goes here -->

    />
    </TableRow>

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

    <!-- Some stuff goes here -->

    />
    </TableRow>

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

    <!-- Some stuff goes here -->

    />
    </TableRow>


</TableLayout>
Run Code Online (Sandbox Code Playgroud)

我的代码比这长得多,但我只是删除了不必要的部分.问题是我想让它成为TableLayout一个可滚动的,这样我的所有东西都可以显示出来.

我试图将此行放入其中TableLayout以使其可滚动:

android:isScrollContainer="true"
Run Code Online (Sandbox Code Playgroud)

但它没有做到这一点.有办法吗?

cit*_*onn 100

把整个事情包括在内:

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="none"
    android:layout_weight="1">
    <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:orientation="vertical">

    ...

</ScrollView>
Run Code Online (Sandbox Code Playgroud)

  • 如果您还需要水平滚动,请参阅http://stackoverflow.com/questions/16623337/how-to-scroll-table-layout-in-horizo​​ntal-and-vertical-in-android (3认同)
  • @citizen为什么要`LinearLayout`? (2认同)
  • @Sudhanshu这篇文章来自3年前,但据我所知,它是将方向设置为垂直的最基本的包装器。 (2认同)
  • 只是爱在Android上有多容易,比较在iOS上做到这一点的痛苦. (2认同)

Art*_*718 19

从技术上讲,您不需要ScrollView中的LinearLayout:

<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="none"
android:layout_weight="1">

    <TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="10dip"
    android:isScrollContainer="true">

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

        <--!Everything Else You Already Have-->

    </TableRow>
 </TableLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

一旦你在ScrollView中占据足够的空间,滚动效果就会激活(有点像HTML TextArea,一旦你有足够的文本行,滚动就会激活.)

您也可以嵌套ScrollView,但在ScrollView中有足够的内容之后,您又感觉不到滚动效果.