how can we make table layout to scroll both ways ( horizontally, vertically)

放肆的年华 提交于 2020-01-01 10:52:13

问题


I am having a table defined in XML file, which currently set to Scroll vertically. But i also want it scroll horizontally as required.

Here is the code of XML in use

<?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>

回答1:


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:




回答2:


You can check this library that I made: https://github.com/InQBarna/TableFixHeaders

It Implements a table that can be filled through an Adapeter. It also recycles views.




回答3:


Does HorizontalScrollView do anything for you?

http://developer.android.com/reference/android/widget/HorizontalScrollView.html

Perhaps add some kind of layout (LinearLayout, Relativelayout, etc.) to the root of your xml?



来源:https://stackoverflow.com/questions/2362460/how-can-we-make-table-layout-to-scroll-both-ways-horizontally-vertically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!