如何使表格布局垂直和水平滚动

How to make a tablelayout scroll vertically and horizontally

如何使表格布局水平和垂直滚动?此表格布局的列是动态生成的。此刻他只是垂直滑动

在某些情况下,表格布局行中包含的信息会太大,您需要水平滑动才能完整查看。

这是我的代码:

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

        <LinearLayout
            android:id="@+id/activity_linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizon`enter code here`tal" >

            <Spinner
                android:id="@+id/activity_spinner1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="start"
                android:drawSelectorOnTop="true"
                style="@android:style/Widget.Holo.Light.Spinner" />

            <EditText
                android:id="@+id/activity_edt1"
                android:labelFor="@+id/consultaCliente_edt1"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:inputType="text"
                style="@style/EditText" >
            </EditText>

            <ImageView
                android:id="@+id/activity_bt1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/bt1"
                android:src="@drawable/search" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/activity_linearLayout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="start"
            android:orientation="horizontal" >

            <Spinner
                android:id="@+id/activity_spinner2"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:gravity="start"
                android:drawSelectorOnTop="true"
                style="@android:style/Widget.Holo.Light.Spinner" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/activity_linearLayout3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="start"
            android:orientation="horizontal" >

            <Spinner
                android:id="@+id/activity_spinner3"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:gravity="start|bottom"
                android:drawSelectorOnTop="true"
                style="@android:style/Widget.Holo.Light.Spinner" />

            <ImageView
                android:id="@+id/activity_bt2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="end"
                android:layout_gravity="end"
                android:contentDescription="@string/bt2"
                android:src="@drawable/information" />

        </LinearLayout>

        <ScrollView
            android:id="@+id/activity_scrollView1"
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="1">

            <TableLayout
                android:id="@+id/activity_tableLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:shrinkColumns="*"
                android:stretchColumns="*" >
            </TableLayout>

        </ScrollView>

        <LinearLayout
            android:id="@+id/activity_linearLayout4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="start"
            android:background="@color/orange"
            android:baselineAligned="false"
            android:orientation="horizontal" >

            <TextView
                android:id="@+id/activity_txt1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingStart="0sp"
                android:paddingEnd="10sp"
                android:text="@string/txt1"
                style="@style/TextViewBlack" />

        </LinearLayout>

    </LinearLayout>

已解决!

    <ScrollView
        android:id="@+id/activity_scrollView1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbars="horizontal|vertical"
        android:scrollbarStyle="outsideInset"
        android:fillViewport="true">

        <HorizontalScrollView
            android:id="@+id/activity_horizontalView1"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:scrollbars="horizontal|vertical">

            <TableLayout
                android:id="@+id/activity_tableLayout1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
            </TableLayout>

        </HorizontalScrollView>

    </ScrollView>