如何使桌面布局垂直和水平滚动

时间:2018-11-09 12:07:25

标签: android scrollview tablelayout horizontalscrollview vertical-scrolling

如何使布局在水平和垂直方向上滚动?该表布局的列是动态生成的。这时他只在垂直滑动。

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

这是我的代码:

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

1 个答案:

答案 0 :(得分:0)

解决了!

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