【问题标题】:Can Table Layout have both horizontal and vertical scroll view表格布局可以同时具有水平和垂直滚动视图吗
【发布时间】:2013-07-08 07:07:01
【问题描述】:

您好,我创建了一个带有普通滚动视图的表格布局,我希望它可以垂直和水平滚动。在 XML 中是否有可能或者是否有任何其他解决方案可以解决,因为我的文本一旦超出长度就会超出表格,并且会使表格布局更大并移出设备。

<ScrollView android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/linearImag">

    <LinearLayout
        android:id="@+id/relativelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

        </LinearLayout>

        <TableLayout
            android:id="@+id/lead_table"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="20dp"
            android:gravity="center"
            android:stretchColumns="*" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <Button
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="25dp"
                    android:background="@drawable/bgbtn"
                    android:text="Lead ID"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textSize="20sp" />
        </TableLayout>

        <Button
            android:id="@+id/btn_add"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginLeft="25dp"
            android:layout_marginTop="20dp"
            android:background="@drawable/add" />

        <TextView
            android:id="@+id/tv_data"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>
    </ScrollView>

【问题讨论】:

    标签: android android-layout android-tablelayout android-scrollview


    【解决方案1】:

    使用水平滚动视图代替普通滚动视图

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

    希望这能解决您的问题:-)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 2015-08-04
      • 2017-10-15
      • 1970-01-01
      • 1970-01-01
      • 2013-05-13
      相关资源
      最近更新 更多