Tvd*_*Tvd 2 android scrollbar width android-tablelayout
我正在活动中显示来自数据库的数据。我想要一个表格和底部的按钮。对于数据,TableLayout将是最佳选择。我将TableLayout添加到HorizontalView和ScrollView中,以使其垂直和水平滚动。正在动态添加所有行-包括标题。这部分工作正常。
我要的是,当内容小于屏幕宽度时,它仍应占据整个屏幕宽度。例如。如果一张桌子非常适合“纵向”模式,那么对于“横向”模式,它们当然将是右边的空白区域。我不希望该空间eb空,而是要被所有列占用。如果行宽大于屏幕宽度,则根本没有问题-出现水平滚动条。
我尝试了几种变体,但没有任何帮助。不知道要进行什么设置以利用所有空间(如果有的话)并显示它。
是的,还有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>
Run Code Online (Sandbox Code Playgroud)
输出:

在解决您的问题时,我发现了一件事,关于在HorizontalScrollView中使用TableLayout的问题。当我们在水平滚动视图中使用表格布局时,android:stretchColumns无法正常工作。这样,当旋转屏幕或列的宽度数据较少时,您将获得空白。
希望您能理解。我试图通过用其他一些替换水平滚动视图来解决此问题。如果有解决办法,我会发布答案。再见
编辑
嗨,电视终于为您解决了问题。对XML布局文件进行以下更改。
在 <HorizontalScrollView>
使用
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
Run Code Online (Sandbox Code Playgroud)
如果要拉伸所有列,请stretchColumns = "*"在TableLayout中使用。
再见 :-)
| 归档时间: |
|
| 查看次数: |
1130 次 |
| 最近记录: |