0

嗨,我创建了一个带有普通滚动视图的表格布局,我希望它可以垂直和水平滚动。在 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>
4

1 回答 1

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>

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

于 2013-09-21T07:55:31.920 回答