2010-03-02 80 views
5

我有一个XML文件中定义的表格,它目前设置为垂直滚动。但我也希望它根据需要水平滚动。我们如何使表格布局滚动双向(水平,垂直)

这里是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> 

回答

8

我有同样的问题,我解决它引入Horizo​​ntalScrollView为滚动型的孩子,然后tableLayout作为Horizo​​ntalScrollView的孩子:

+0

这不是一个好的解决方案,因为用户不能同时以两种方式(垂直和水平)滚动。 – chteuchteu 2014-01-31 18:03:05

2

您可以检查此我制作的库:https://github.com/InQBarna/TableFixHeaders

它实现了一个可以通过Adapeter填充的表格。它也回收意见。

+0

检查了这个代码,它很好。该项目很容易导入到Mac上的eclipse,但在windows上转移到eclipse是一件痛苦的事情。 [Linux的差距?]。这是一个反复出现的问题。 – 2013-03-24 10:58:56