Enmanuel Grullard
Enmanuel Grullard

Reputation: 1

Error :Exception raised during rendering: ScrollView can host only one direct child

I'm trying to design an app, but when I put a ScrollView throughout the body says

Exception raised During rendering: ScrollView can host only one direct child

What am I doing wrong?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/root">

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


    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/toolbar"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@+id/title"
        android:layout_alignStart="@+id/title" />


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:background="#303F9F"
        android:id="@+id/layout">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/title"
            android:gravity="center"
            android:hint="Title"
            android:textSize="23dp"
            android:text="@string/contenido"
            android:textColor="#fff"
            android:layout_gravity="center"
            android:layout_marginLeft="35dp"
            android:layout_marginRight="35dp"
            android:layout_marginTop="140dp"/>

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/view_include_footer"
            android:layout_alignParentBottom="true"
            />


    </RelativeLayout>
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/comment_rv"
            android:layout_below="@+id/setting_toolbar"
            android:scrollbars="vertical"
            android:background="#ccffffff"
            />
    </RelativeLayout>
    </ScrollView>

</LinearLayout>

Upvotes: 0

Views: 1681

Answers (2)

Eric Chang
Eric Chang

Reputation: 1

I met this problem in the earlier time, it's obvious that ScrollView can host only one direct child. It means that you should not use two! Child view <include/> and <RelativeLayout /> in the ScrollView, just surround a RelativeLayout outer of the two child view.

Upvotes: 0

xblack
xblack

Reputation: 571

ScrollView can host only one direct child means that you can use one element directly within it. Create a RelativeLayout or what suits you best and put your include and both the RelativeLayouts within it and put this layout within ScrollView. You'll have one direct child only this way.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/root">

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

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

<include
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    layout="@layout/toolbar"
    android:layout_alignParentTop="true"
    android:layout_alignLeft="@+id/title"
    android:layout_alignStart="@+id/title" />


<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="400dp"
    android:background="#303F9F"
    android:id="@+id/layout">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/title"
        android:gravity="center"
        android:hint="Title"
        android:textSize="23dp"
        android:text="@string/contenido"
        android:textColor="#fff"
        android:layout_gravity="center"
        android:layout_marginLeft="35dp"
        android:layout_marginRight="35dp"
        android:layout_marginTop="140dp"/>

    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/view_include_footer"
        android:layout_alignParentBottom="true"
        />


</RelativeLayout>
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/comment_rv"
        android:layout_below="@+id/setting_toolbar"
        android:scrollbars="vertical"
        android:background="#ccffffff"
        />
</RelativeLayout>
</RelativeLayout>
</ScrollView>

Upvotes: 3

Related Questions