在 ScrollView 中拉伸 TableLayout
我有这个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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果只有一列,
android:stretchColumns="1"
将不会执行任何操作,因为该数字表示要拉伸的列的索引(0 是第一列的索引)。尝试使用android:stretchColumns="*"
编辑: 再考虑一下,我怀疑
fill_parent
实际上会对 <代码>horizontalScrollView。因为视图在水平方向上无限滚动,所以我认为 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 usingandroid:stretchColumns="*"
EDIT: thinking about this a little more, I doubt
fill_parent
will actually have any effect on thehorizontalScrollView
. Because the view is infinitely scrollable in the horizontal direction, I don't think android takes thelayout_width
into account unless it is a hard-coded value. You can try setting thelayout_width
to the same size as your screen (maybe get the width of your screen and set it as a minimum width in code?).我得到了它。答案是:在ScrollView中设置:
I got it. The answer is: Set this in ScrollView: