Fix Scrollview can Host Only One Direct Child in Android

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.

Advertisements


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>

Post navigation

Comments

This site uses Akismet to reduce spam. Learn how your comment data is processed.