首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何制作一个可滚动的TableLayout?

如何制作一个可滚动的TableLayout?
EN

Stack Overflow用户
提问于 2011-06-29 06:15:04
回答 4查看 77K关注 0票数 60

请看这里的XML代码:

代码语言:javascript
复制
<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>

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

我尝试将这一行放在TableLayout中,以便使其可滚动:

代码语言:javascript
复制
android:isScrollContainer="true"

但它并不能完成这项工作。有办法吗?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-06-29 06:19:19

将整个过程包含在:

代码语言:javascript
复制
<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>
票数 106
EN

Stack Overflow用户

发布于 2014-08-27 08:37:21

从技术上讲,您不需要在ScrollView中使用LinearLayout:

代码语言:javascript
复制
<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>

一旦你在ScrollView中占据了足够的空间,滚动效果就会激活(有点像超文本标记语言的TextArea,一旦你有足够的文本行,滚动就会激活)。

您也可以嵌套ScrollView,但是在ScrollView中有足够的内容之前,您仍然无法感受到滚动效果。

票数 28
EN

Stack Overflow用户

发布于 2014-12-26 19:58:06

谢谢mbauer,它解决了我的问题,我把它放在首位

带end的

  1. TableLayout
  2. TableRow (用于columns)
  3. ScrollView
  4. LinearLayout
  5. x TableRow with end
  6. end TableLayout

的页眉

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6513718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档