Android 我们如何使表格布局双向滚动(水平、垂直)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2362460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how can we make table layout to scroll both ways ( horizontally, vertically)
提问by Amit
I am having a table defined in XML file, which currently set to Scroll vertically. But i also want it scroll horizontally as required.
我在 XML 文件中定义了一个表,该表当前设置为垂直滚动。但我也希望它根据需要水平滚动。
Here is the code of XML in use
这是正在使用的 XML 代码
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1,2"
android:id="@+id/tLayout"
android:scrollbars="vertical"
>
<TableRow
android:layout_width="fill_parent">
<TextView
android:padding="3dip"
android:gravity="left"
android:text="Name"
/>
<TextView
android:padding="3dip"
android:gravity="left"
android:text="Address"
/>
<TextView
android:padding="3dip"
android:gravity="left"
android:text="Age"
/>
</TableRow>
</TableLayout>
</ScrollView>
回答by Nemesis
I had the same problem and I solved it introducing a HorizontalScrollView as a child of the ScrollView and then the tableLayout as a child of the HorizontalScrollView:
我遇到了同样的问题,我解决了它,将 HorizontalScrollView 作为 ScrollView 的子项,然后将 tableLayout 作为 HorizontalScrollView 的子项:
回答by Brais Gabin
You can check this library that I made: https://github.com/InQBarna/TableFixHeaders
您可以查看我制作的这个库:https: //github.com/InQBarna/TableFixHeaders
It Implements a table that can be filled through an Adapeter. It also recycles views.
它实现了一个可以通过 Adapeter 填充的表。它还回收视图。
回答by edwardsharp
Does HorizontalScrollView do anything for you?
HorizontalScrollView 对你有什么帮助吗?
http://developer.android.com/reference/android/widget/HorizontalScrollView.html
http://developer.android.com/reference/android/widget/HorizontalScrollView.html
Perhaps add some kind of layout (LinearLayout, Relativelayout, etc.) to the root of your xml?
也许在您的 xml 的根目录中添加某种布局(LinearLayout、Relativelayout 等)?