在 ScrollView 中拉伸 TableLayout

发布于 2024-12-01 09:50:59 字数 888 浏览 1 评论 0原文

我有这个TableLayout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout" android:layout_height="fill_parent"
android:layout_alignParentBottom="true" android:scrollbars="horizontal|vertical"
android:layout_width="fill_parent" android:scrollbarStyle="outsideInset">
<HorizontalScrollView android:id="@+id/horizontalView" android:layout_height="fill_parent"
            android:layout_width="fill_parent">
    <TableLayout android:id="@+id/reportTableLayout"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:stretchColumns="1">
    </TableLayout>
</HorizontalScrollView>
</ScrollView>

我已将所有layout_width 设置为fill_parent,但我的Table 列似乎没有拉伸并填充其余的宽度空间。左侧仍有空白,但我希望我的表格能够延伸到屏幕的整个宽度。有什么想法吗?谢谢。

I have this TableLayout:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout" android:layout_height="fill_parent"
android:layout_alignParentBottom="true" android:scrollbars="horizontal|vertical"
android:layout_width="fill_parent" android:scrollbarStyle="outsideInset">
<HorizontalScrollView android:id="@+id/horizontalView" android:layout_height="fill_parent"
            android:layout_width="fill_parent">
    <TableLayout android:id="@+id/reportTableLayout"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:stretchColumns="1">
    </TableLayout>
</HorizontalScrollView>
</ScrollView>

I have set all layout_width to fill_parent, and yet my Table columns don't seem to stretch and fill the rest of the width space. There is still a margin on the left, but I want my table to stretch over the complete width of the screen. Any ideas? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎会甘心 2024-12-08 09:51:00

如果只有一列,android:stretchColumns="1" 将不会执行任何操作,因为该数字表示要拉伸的列的索引(0 是第一列的索引)。尝试使用 android:stretchColumns="*"

编辑: 再考虑一下,我怀疑 fill_parent 实际上会对 <代码>horizo​​ntalScrollView。因为视图在水平方向上无限滚动,所以我认为 android 不会考虑 layout_width ,除非它是一个硬编码值。您可以尝试将 layout_width 设置为与屏幕相同的大小(也许获取屏幕的宽度并将其设置为代码中的最小宽度?)。

If you only have one column, android:stretchColumns="1" won't do anything, because the number represents the index of the column to stretch (with 0 being the index of the first column). Try using android:stretchColumns="*"

EDIT: thinking about this a little more, I doubt fill_parent will actually have any effect on the horizontalScrollView. Because the view is infinitely scrollable in the horizontal direction, I don't think android takes the layout_width into account unless it is a hard-coded value. You can try setting the layout_width to the same size as your screen (maybe get the width of your screen and set it as a minimum width in code?).

花落人断肠 2024-12-08 09:50:59

我得到了它。答案是:在ScrollView中设置:

android:fillViewport="true"

I got it. The answer is: Set this in ScrollView:

android:fillViewport="true"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文