2013-05-18 130 views
17

我在表格佈局中完全困惑。我必須實現水平和垂直滾動的表格。我也看到表修復頭示例,但tablefixheader示例已使用適配器來設置數據,但我需要表格佈局中的添加視圖方法。 我用下面的代碼,但它不能支持雙向滾動如何在android中水平和垂直滾動表格佈局

 <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scrollbars="vertical" > 

     <HorizontalScrollView 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      android:fadeScrollbars="false"> 

      <TableLayout 
       android:id="@+id/tableLayoutId" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     </HorizontalScrollView> 
    </ScrollView> 

回答

46

這是我如何實現它和我的作品:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 
<ScrollView 
    android:id="@+id/layout" 
    android:layout_height="match_parent"   
    android:scrollbars="horizontal|vertical" 
    android:layout_width="match_parent"  
    android:layout_marginTop="5dip"  
    android:scrollbarStyle="outsideInset" 
    android:fillViewport="true"> 

    <HorizontalScrollView 
     android:id="@+id/horizontalView" 
     android:layout_height="wrap_content"  
     android:scrollbars="horizontal|vertical" 
     android:layout_width="wrap_content"  
     android:layout_marginTop="5dip"> 

     <TableLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/tlGridTable" > 
     </TableLayout> 
    </HorizontalScrollView> 
</ScrollView> 
</LinearLayout> 

這個代碼看看,看看這個幫助。

+1

感謝和它的作品真棒...... – user1811379

+1

@ user1811379,歡迎你,有一個很好的編碼。 –

+1

很棒的+1。你應該添加一點解釋它爲什麼工作=) – user2336315

0

添加這樣

<ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:scrollbars="vertical"> 

     <HorizontalScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <android.support.v7.widget.RecyclerView 
       android:id="@+id/rv_pins" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scrollbarStyle="outsideOverlay" 
       android:scrollbars="horizontal" /> 
     </HorizontalScrollView> 

    </ScrollView>