"ScrollView can host only one direct child" only in Landscape mode

1.3k views Asked by At

I'm trying to use ScrollView and it works fine in Portrait mode but doesn't in Landscape mode. When I start the app, everything's fine but when I turn my phone on the side I have the "ScrollView can host only one direct child" Exception.

Here is my XML code :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="180dp">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/content_show_details_fragment_picture"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/boiler_room"
                android:scaleType="centerCrop"
                android:alpha="0.8"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/content_show_details_fragment_title"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:text="Titre de l'émission"
                android:layout_above="@+id/content_show_details_fragment_subtitle"
                android:layout_marginStart="10dp"
                android:textColor="@android:color/white"
                android:background="@android:color/black"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Subtitle"
                android:id="@+id/content_show_details_fragment_subtitle"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:layout_alignParentBottom="true"
                android:layout_alignParentStart="true"
                android:layout_marginStart="10dp"
                android:layout_marginBottom="10dp"
                android:textColor="@android:color/white"
                android:background="@android:color/black"/>

        </RelativeLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Prochaine diffusion"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:layout_marginTop="10dp"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/content_show_details_fragment_date"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:layout_marginStart="10dp"
                android:text="11/11/2014 à 18h00"/>

        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginTop="10dp"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:text="Podcasts"/>

            <ListView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/content_show_details_fragment_listView"/>

        </LinearLayout>
    </LinearLayout>
</ScrollView>

And the Exceptions :

11-25 21:21:57.289  17419-17419/com.readyo.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.readyo.app, PID: 17419
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.readyo.app/com.readyo.app.MainActivity}: java.lang.IllegalStateException: ScrollView can host only one direct child
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2394)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2452)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4035)
            at android.app.ActivityThread.access$1000(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5586)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
            at android.widget.ScrollView.addView(ScrollView.java:387)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:901)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
            at android.app.BackStackRecord.run(BackStackRecord.java:684)
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1453)
            at android.app.Activity.performStart(Activity.java:5460)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2367)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2452)
            at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4035)
            at android.app.ActivityThread.access$1000(ActivityThread.java:172)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5586)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
            at dalvik.system.NativeStart.main(Native Method)
0

There are 0 answers