Asked 4 years ago
24 Dec 2020
Views 4822

posted

Scrollview can host only one direct child

using ScrollView for scrollable layout

and


     <ScrollView
                        android:layout_width="match_parent"
    
                         
                        android:layout_height="200dp"
                         >
                        <LinearLayout android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                             
    
                            android:orientation="vertical" >
    Here some sub elements
    
                         </LinearLayout>

 <LinearLayout android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                             
    
                            android:orientation="vertical" >
    Here some sub elements
    
                         </LinearLayout>
                    </ScrollView>


but getting error scrollview can host only one direct child

how to solve this scrollview can host only one direct child error ?
jaman

jaman
answered Nov 30 '-1 00:00

you can put LinearLayout or RelativeLayout or any layout to direct one children at ScrollView and all those children goes to under LinearLayout or RelativeLayout , instead of direct under ScrollView


<ScrollView
 android:layout_width="match_parent"
 android:layout_height="200dp"  >
	<LinearLayout android:layout_width="match_parent"
         android:layout_height="wrap_content"
        android:orientation="vertical" >

     <TextView
 android:layout_width="match_parent"
android:layout_height="wrap_content" />

        <TextView
 android:layout_width="match_parent"
android:layout_height="wrap_content" />

   </LinearLayout>
	 
</ScrollView>
Post Answer