【发布时间】:2016-08-19 16:17:34
【问题描述】:
我有一个 TableLayout 动态填充了多行数据。它包含的数据比屏幕所能容纳的多,所以我要求它是可滚动的。
我的问题是,当我将 TableLayout 放在 ScrollView 中时,它似乎从 TableLayout 的顶部切断了许多行。
作为参考,完整的代码在这里(问题是已经杂乱无章以适应一切)http://pastebin.com/w7Fi3Bzz
请参阅下面与我遇到的问题相关的代码
这是没有 ScrollView 的 XML:
<TableLayout
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:id="@+id/tbl_statistics"
android:stretchColumns="*"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
</TableLayout>
它是什么样子的:
这是带有封闭 ScrollView 的同一个 XML:
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<TableLayout
android:orientation="vertical"
android:fillViewport="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:id="@+id/tbl_statistics"
android:stretchColumns="*"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
>
</TableLayout>
</ScrollView>
这是表格的样子,您可以看到表格顶部被截断(填充了完全相同的数据):
我在这里LinearLayout not expanding inside a ScrollView 发现了类似的问题,但答案对我没有帮助。
【问题讨论】:
-
第二个布局中不需要
LinearLayout。 -
@MikeM。无论我是否包含它,这个问题仍然存在
-
我第二个@MikeM。
LinearLayout是多余的。当您删除LinearLayout时,您应该将layout_height的TableLayout设置为wrap_content -
尝试删除
TableLayout中的layout_gravity属性,不带LinearLayout。此外,fillViewport对ScrollView以外的任何内容都无用。 -
好吧,伙计们,我将删除它以简化我的问题,但我已经尝试了两种方式,但它仍然被截断
标签: android xml scrollview tablelayout