我正在尝试实现一个 UI,其中包含使用 TableLayout
显示的数据表(动态填充)。我希望默认显示表格的 4 列,并能够水平滚动表格以显示 4(或更多)个附加列。将 TableLayout
与水平/垂直 ScrollView
结合使用是否可行?如果有任何展示这种风格的 XML 示例,我将不胜感激。
这里有一个例子来说明:
默认表格 View
向右滚动后查看
最佳答案
您应该能够通过将 TableLayout 放在 HorizontalScrollView 中来实现这一点。在 TableLayout 中定义元素的宽度
像这样的(我没有测试过):
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/hsv1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout android:layout_height="wrap_content"
android:gravity="center"
android:layout_width="wrap_content"
android:id="@+id/tl1"
android:scrollbars="horizontal">
// Your other elements go here.
</TableLayout>
</HorizontalScrollView>
关于安卓用户界面 : Multiple Horizontally Paged Table,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6363743/