ScrollView只能托管一个直接子项,但我只有一个

时间:2015-08-31 14:38:39

标签: android scrollview

我知道有一些问题存在同样的问题但是没有问题对我有用。这是我的xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="@drawable/hatter">
    <TableLayout
        android:id="@+id/TableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:stretchColumns="0"
        tools:context="hu.szada.examplefortable.MainActivity" >

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Szint 1"
                android:textSize="30dp"
                android:layout_centerHorizontal="true"
                android:textColor="#12222a" />
        </RelativeLayout>

        <TableRow
            android:id="@+id/TableRow1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/ajandekboltbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/ajandekbolt" />
                <ImageView
                    android:id="@+id/ajandekboltpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        // ROW 2

        <TableRow
            android:id="@+id/TableRow2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/akciofilmbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/akciofilm" />
                <ImageView
                    android:id="@+id/akciofilmpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 3

        <TableRow
            android:id="@+id/TableRow3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/babakocsibutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/babakocsi" />
                <ImageView
                    android:id="@+id/babakocsipipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 4

        <TableRow
            android:id="@+id/TableRow4"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/csirkefogobutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/csirkefogo" />
                <ImageView
                    android:id="@+id/csirkefogopipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 5

        <TableRow
            android:id="@+id/TableRow5"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/elemlampabutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/elemlampa" />
                <ImageView
                    android:id="@+id/elemlampapipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 6

        <TableRow
            android:id="@+id/TableRow6"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/evkonyvbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/evkonyv" />
                <ImageView
                    android:id="@+id/evkonyvpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 7

        <TableRow
            android:id="@+id/TableRow7"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/foghazbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/foghaz" />
                <ImageView
                    android:id="@+id/foghazpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 8

        <TableRow
            android:id="@+id/TableRow8"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/foldgombbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/foldgomb" />
                <ImageView
                    android:id="@+id/foldgombpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 9

        <TableRow
            android:id="@+id/TableRow9"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/franciaagybutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/franciaagy" />
                <ImageView
                    android:id="@+id/franciaagypipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 10

        <TableRow
            android:id="@+id/TableRow10"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/gyongyszembutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/gyongyszem" />
                <ImageView
                    android:id="@+id/gyongyszempipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 11

        <TableRow
            android:id="@+id/TableRow11"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/gyujtozsinorbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/gyujtozsinor" />
                <ImageView
                    android:id="@+id/gyujtozsinorpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 12

        <TableRow
            android:id="@+id/TableRow12"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/hatszogbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/hatszog" />
                <ImageView
                    android:id="@+id/hatszogpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 13

        <TableRow
            android:id="@+id/TableRow13"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/kartyavarbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/kartyavar" />
                <ImageView
                    android:id="@+id/kartyavarpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 14

        <TableRow
            android:id="@+id/TableRow14"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/kulonosbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/kulonos" />
                <ImageView
                    android:id="@+id/kulonospipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 15

        <TableRow
            android:id="@+id/TableRow15"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/szarkalabbutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/szarkalab" />
                <ImageView
                    android:id="@+id/szarkalabpipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>

        //ROW 16

        <TableRow
            android:id="@+id/TableRow16"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="30dp"
            android:layout_alignParentRight="true" >

            <RelativeLayout android:layout_height="wrap_content"
                android:layout_width="wrap_content">

                <ImageButton
                    android:id="@+id/tollseprubutton"
                    android:layout_width="match_parent"
                    android:layout_height="130dp"
                    android:background="@drawable/tollsepru" />
                <ImageView
                    android:id="@+id/tollseprupipa"
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_centerVertical="true"
                    android:src="@drawable/pipalista"
                    android:visibility="invisible"/>
            </RelativeLayout>
        </TableRow>
    </TableLayout>

</LinearLayout>
</ScrollView>

我只有一个孩子是LinearLayout,在布局中我有其他视图。我不知道我的代码有什么问题。

1 个答案:

答案 0 :(得分:0)

我有同样的问题。由于此布局文件而未抛出错误,但由于另一个提供了ViewGroup。我假设您正在向活动添加片段(使用该布局文件)。 我的错是我将片段添加到已经是ScrollView的现有ViewGroup。因此,我的Activity上的ScrollView有2个后代。

解决方案:在Activity上围绕ScrollView包装FrameLayout,然后将Fragment添加到FrameLayout