我在活动中显示来自数据库的数据。我想要一个桌子和底部的按钮。对于数据来说,TableLayout 是最好的选择。我将 TableLayout 添加到 HorizontalView 和 ScrollView 中,使其垂直和水平滚动。动态添加所有行 - 包括标题。这部分工作正常。
我想要的是当内容小于屏幕宽度时,它应该占据整个屏幕宽度。例如。如果桌子适合纵向模式,那么当然对于横向模式,它们将在右侧留下空白区域。我不希望该空间为空,而是被所有列占据。如果行宽大于屏幕宽度,则完全没有问题 - 因为会出现水平滚动条。
我尝试了一些变化,但没有任何帮助。知道要进行哪些设置来利用所有空间(如果有的话)并显示它。
是的,还有一个水平滚动条问题,它出现在最后一行。我想要它
出现在最后一行下方 - 因此最后一行的边框可见。我的XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical">
<HorizontalScrollView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp" >
<TableLayout android:id="@+id/browseTable" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginBottom="20dp"
android:background="#FF0000" android:stretchColumns="1,2,3">
</TableLayout>
</HorizontalScrollView>
</ScrollView>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:gravity="center"
android:layout_marginTop="15dp">
<Button android:id="@+id/browseAddBtn" android:text="Add" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginRight="10dp" />
<Button android:id="@+id/browseViewBtn" android:text="Edit" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:layout_marginRight="10dp" />
<Button android:id="@+id/browseReturnBtn" android:text="Return" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
OUTPUT :
我在解决你的问题时发现了一件事,关于表格布局当在内部使用时水平滚动视图. The android:stretchColumns当我们在水平滚动视图中使用表格布局时,它不起作用。这样,当屏幕旋转或列的宽度数据较小时,您就会得到空白空间。
我希望你明白这一点。我试图通过用其他视图替换水平滚动视图来解决这个问题。如果我得到解决方案,我会发布答案。再见。
EDIT
Hi Tvd最后我得到了你的问题的解决方案。对 XML 布局文件进行以下更改。
In <HorizontalScrollView>
use
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
Use stretchColumns = "*"
in 表格布局如果您希望拉伸所有列。
再见。 :-)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)