-1

I hava a ScrollView with one RelativeLayout as a direct child, and multiple layouts inside it. However, at runtime the app crashes, saying ScrollView can have only one direct child. What is the mistake I am making. P.S. Sorry if the question was stupid, I have no experience with Android Programming.

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.appex.android.inquisitor.QuestionActivity"
android:background="@drawable/bg" >
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView
        android:textStyle="bold"
        android:id="@+id/textviewname"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:layout_marginTop="150dp"
        android:textColor="@color/text2"
        android:textSize="13pt"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <EditText
        android:id="@+id/edittext1"
        android:layout_width="fill_parent"
        android:maxLines="1"
        android:layout_height="wrap_content"
        android:inputType="text"
        android:textSize="12pt"
        android:textColor="@color/text2"
        android:imeOptions="actionDone"
        android:layout_gravity="center"
        android:layout_below="@+id/textviewname"
        android:layout_marginTop="15dp"

    />
    <TextView
        android:layout_width="wrap_content"
        android:textStyle="bold"
        android:layout_height="wrap_content"
        android:id="@+id/hintview"
        android:textSize="12pt"
        android:textColor="@color/text2"
        android:layout_below="@+id/edittext1"
        android:layout_marginTop="10dp"
        android:layout_centerHorizontal="true" />
    <Button
        android:id="@+id/done_button"
        android:textSize="12pt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textStyle="bold"
        android:text="@string/done_button"
        android:background="@android:color/transparent"
        android:textColor="@color/text2"
        android:layout_alignTop="@+id/hintbutton"
        android:layout_marginLeft="189dp"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12pt"
        android:textStyle="bold"
        android:id="@+id/hintbutton"
        android:text="@string/hintbutton"
        android:background="@android:color/transparent"
        android:textColor="@color/text2"
        android:layout_marginLeft="101dp"
        android:layout_marginTop="14dp"
        android:layout_below="@+id/hintview"
         />
    <TextView
        android:id="@+id/attemptview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/text2"
        android:textSize="10pt"
        android:layout_marginTop="75dp"
        android:layout_alignLeft="@+id/done_button"
        android:layout_alignStart="@+id/done_button"
    />
</RelativeLayout>
</ScrollView>
l-l
  • 3,804
  • 6
  • 36
  • 42
Anuraag Baishya
  • 874
  • 2
  • 11
  • 26

2 Answers2

0

You should wrap everything within the scrollView in a LinearLayout with wrap_content for the height.

This question is already answered here:

Scrollview can host only one direct child

Community
  • 1
  • 1
l-l
  • 3,804
  • 6
  • 36
  • 42
0

Try adding a Relative layout before ScrollingView.

sunnytheshine
  • 149
  • 11