我正在一个活动中显示来自数据库的数据。我想要一张桌子和底部的扣子。对于数据来说,tablelayout是最好的选择。我将tablelayout添加到horizontalview&滚动视图,使其垂直和水平滚动。动态添加所有行-包括标题。这部分工作正常。
我要的是当内容小于屏幕宽度时,它还应该占据整个屏幕宽度。例如,如果一张桌子在纵向模式下很适合,那么当然在横向模式下,它们在右边的空白处是空白的。我不希望那个空间是空的,而是被所有的列占据。如果行宽度大于屏幕宽度,则根本没有问题-显示水平滚动条。
我尝试了一些变化,但没有任何帮助。知道要设置什么来使用所有空间(如果是avbl的话)并显示出来。
是的,还有一期的水平滚动条,它就出现在最后一行。我希望它
显示在最后一行下面-因此最后一行的边框可见。我的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>

输出:

最佳答案

我在解决你的问题时发现了一件事,关于在水平滚动视图中使用的TableLayout。当我们在水平滚动视图中使用表布局时,android:stretchcolumns不起作用。这样,当屏幕旋转或列具有较少宽度数据时,将获得空白。
希望你能理解。我试图通过用其他视图替换水平滚动视图来解决这个问题。如果我得到解决方案,我将发布答案。再见。
编辑
我终于找到了解决你问题的办法。对XML布局文件进行以下更改。
<HorizontalScrollView>
使用

        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"

如果要拉伸所有列,请在TableLayout中使用stretchColumns = "*"
再见。:-)

08-18 16:48
查看更多