Fix Scrollview can Host Only One Direct Child in Android
Wednesday, November 15, 2023, 6 AM
How to Solve Android Studio Error Scrollview can Host Only One Direct Child Android Studio
This is a common error and what this error means is that in Scrollview, you can only add one child - that means, you can only directly put one view like imageview, textview or one edittext,one layout etc.
If you need to put many views and elements in scrollview, you can put all children in a Linearlayout and place the Linearlayout inside the Scrollview, below is an example
<ScrollView android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/brand" android:text="@string/brand" android:layout_width="match_parent" android:layout_height="wrap_content" /> <EditText android:id="@+id/edxbrand" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout> </ScrollView>
No comments found.