我在活动中显示来自数据库的数据。我想要一个表格和底部的按钮。对于数据认为 TableLayout 将是它的最佳选择。我将 TableLayout 添加到 HorizontalView 和 ScrollView 使其垂直和水平滚动。我正在动态添加所有行 - 包括标题。这部分工作正常。
我想要的是当内容小于屏幕宽度时,它应该占据整个屏幕宽度。例如。如果一张桌子在纵向模式下非常适合,那么对于横向模式,它们的右侧将是空白区域。我不希望那个空间是空的,而是被所有列占据。如果行宽大于屏幕宽度,则根本没有问题 - 因为出现水平滚动条。
我尝试了一些变化,但没有任何帮助。知道要进行哪些设置以利用所有空间(如果有的话)并显示它。
是的,还有 1 个水平滚动条问题,它只出现在最后一行。我希望它出现在最后一行下方 - 所以最后一行的边框是可见的。我的 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>
输出 :