【发布时间】:2012-02-16 15:22:52
【问题描述】:
我在 Activity 中显示来自 DB 的数据。我想要一个表格和底部的按钮。对于数据认为 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>
输出:
【问题讨论】:
-
捕捉这张图片,并添加到这里,然后告诉你到底想要什么。它会帮助其他人帮助你。 :) 谢谢
-
@AnkitA,添加了一张图片来展示我拥有的东西并解释我想要的东西。希望它会帮助其他人帮助我。
-
尝试我的回答不是全部,但是是的,您的一些问题将由此解决。第二,如果你想显示浮点值。尝试展示到一定长度。小数点后4位..
-
@AnkitA, REG 显示浮点值:我没明白你的意思我的意思是怎么做?我只是获取值,将其转换为 String() 并在 TextView 中设置数据: obj.getValue(field).toString()
-
你可以像 obj.getValue(field).toString().substring(0,7) 那样做,或者你可以得到 '.' 的索引。并且可以说 substring.(0,str.indexof(",")+4) 像 dat
标签: android width scrollbar android-tablelayout