Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在表格布局中添加滚动视图?_Android_Scrollview_Tablelayout - Fatal编程技术网

Android 如何在表格布局中添加滚动视图?

Android 如何在表格布局中添加滚动视图?,android,scrollview,tablelayout,Android,Scrollview,Tablelayout,这是我第一次使用Scrollview,我想用tablelayout 3x8行创建应用程序。行的大小、高度和宽度相同,并且表格可以垂直滚动。如何在xml布局中做到这一点?谢谢你的帮助 <ScrollView android:id="@+id/layout" android:layout_height="match_parent" android:scrollbars="vertical" android:layout_width="match_parent"

这是我第一次使用Scrollview,我想用tablelayout 3x8行创建应用程序。行的大小、高度和宽度相同,并且表格可以垂直滚动。如何在xml布局中做到这一点?谢谢你的帮助

<ScrollView android:id="@+id/layout"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    android:layout_width="match_parent"
    android:layout_marginTop="5dip"
    android:scrollbarStyle="outsideInset"
    android:fillViewport="true"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="*"
    >
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
</TableLayout>

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="*"
    >
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
    <TableRow
        android:layout_weight="1"
        android:gravity="center">
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
    </TableRow>
</TableLayout>
    </LinearLayout>
</ScrollView>

这是一种方法,您必须手动指定
表格行的高度,以便按如下方式实现此目的

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <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"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <LinearLayout
            android:layout_width="match_parent" android:orientation="vertical"
            android:layout_height="match_parent">

            <TableRow
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="100dp">
                <Button android:layout_weight="1" android:text="Button" android:layout_width="match_parent" android:layout_height="match_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
            </TableRow>
            <TableRow
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="100dp">
                <Button android:layout_weight="1" android:text="Button" android:layout_width="match_parent" android:layout_height="match_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
            </TableRow>
            <TableRow
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="100dp">
                <Button android:layout_weight="1" android:text="Button" android:layout_width="match_parent" android:layout_height="match_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
            </TableRow>
            <TableRow
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="100dp">
                <Button android:layout_weight="1" android:text="Button" android:layout_width="match_parent" android:layout_height="match_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
            </TableRow>
            <TableRow
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="100dp">
                <Button android:layout_weight="1" android:text="Button" android:layout_width="match_parent" android:layout_height="match_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
            </TableRow>
            <TableRow
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="100dp">
                <Button android:layout_weight="1" android:text="Button" android:layout_width="match_parent" android:layout_height="match_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
            </TableRow>
            <TableRow
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="100dp">
                <Button android:layout_weight="1" android:text="Button" android:layout_width="match_parent" android:layout_height="match_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
            </TableRow>
            <TableRow
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="100dp">
                <Button android:layout_weight="1" android:text="Button" android:layout_width="match_parent" android:layout_height="match_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
                <Button android:layout_weight="1" android:text="Button" android:layout_width="fill_parent" android:layout_height="fill_parent"/>
            </TableRow>

        </LinearLayout>
    </ScrollView>

</LinearLayout>  


实现这一点的另一种方法是使用
GridView
RecyclerView
<代码>回收视图
是实现这一点的最简单方法。我希望它对你有用。谢谢

滚动视图
中删除
线性布局
,然后重试,如果不起作用,请使用此选项

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="200dp" >
            <EditText
                android:layout_weight="1"
                android:background="#F00"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#FF0"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#F0F"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="100dp">
            <EditText
                android:layout_weight="1"
                android:background="#F00"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#FF0"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#F0F"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="100dp">
            <EditText
                android:layout_weight="1"
                android:background="#F00"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#FF0"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#F0F"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="100dp">
            <EditText
                android:layout_weight="1"
                android:background="#F00"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#FF0"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#F0F"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="100dp">
            <EditText
                android:layout_weight="1"
                android:background="#F00"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#FF0"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#F0F"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </TableRow>

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_marginTop="100dp">
            <EditText
                android:layout_weight="1"
                android:background="#F00"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#FF0"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
            <EditText
                android:layout_weight="1"
                android:background="#F0F"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </TableRow>
    </TableLayout>
</ScrollView>


Use TabLayout property look:app:tabMode=“scrollable”可能已经帮了我大忙了。谢谢先生,它解决了我的部分问题@User6829548Welcome@Denny。谢谢先生,这对我很有帮助。谢谢先生,我尝试删除我的线性布局它不起作用。谢谢你的回答