How to scroll table layout in horizontal and verti

2019-01-13 18:43发布

I am totally confused in table layout scroll. I have to implement table with horizontal and vertical scrolling. I have also saw table fix header example but tablefixheader sample have used adapter to set data but i require add-view method in table layout. I have used below code but it couldn't support both ways scrolling

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

2条回答
叼着烟拽天下
2楼-- · 2019-01-13 18:57

This is how I implemented it and works for me:

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

Take a look at this code and see if this helps.

查看更多
We Are One
3楼-- · 2019-01-13 19:12

add like this

<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>
查看更多
登录 后发表回答