1

I m using android studio 1.0.... In design ,my screen is get filled and when it runs it needs to scroll down but its not ... I tried previous answers an add scroll view in layout but there is error ( Scroll view can host only one child) enter code here

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/ScrollView">


<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="INTRODUCTION:"
    android:id="@+id/heading1"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:textAlignment="center"
    android:phoneNumber="false"
    android:textStyle="bold" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="@string/Introduction"
    android:id="@+id/textView2"
    android:layout_below="@+id/heading1"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="10dp"
    android:layout_marginStart="10dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="HYDROCARBON:"
    android:id="@+id/textView3"
    android:layout_below="@+id/textView2"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:textStyle="bold" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="@string/hydrocarbon"
    android:id="@+id/textView4"
    android:layout_below="@+id/textView3"
    android:layout_alignLeft="@+id/textView2"
    android:layout_alignStart="@+id/textView2" />

<ImageView
    android:layout_width="150dp"
    android:layout_height="150dp"
    android:id="@+id/imageView"
    android:layout_below="@+id/textView4"
    android:layout_centerHorizontal="true"
    android:src="@drawable/ethane"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="TYPES OF HYDROCARBON:"
    android:id="@+id/textView5"
    android:layout_below="@+id/imageView"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:textStyle="bold" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="@string/types"
    android:id="@+id/textView6"
    android:layout_below="@+id/textView5"
    android:layout_alignLeft="@+id/textView4"
    android:layout_alignStart="@+id/textView4" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Alkane"
    android:id="@+id/textView7"
    android:layout_below="@+id/textView6"
    android:layout_alignLeft="@+id/textView6"
    android:layout_alignStart="@+id/textView6" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Alkene"
    android:id="@+id/textView8"
    android:layout_below="@+id/textView7"
    android:layout_alignLeft="@+id/textView7"
    android:layout_alignStart="@+id/textView7" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="Alkyne"
    android:id="@+id/textView9"
    android:layout_below="@+id/textView8"
    android:layout_alignLeft="@+id/textView8"
    android:layout_alignStart="@+id/textView8" />

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="BACK"
    android:id="@+id/button2"
    android:onClick="mainPage"
    android:layout_below="@+id/textView9"
    android:layout_alignRight="@+id/textView8"
    android:layout_alignEnd="@+id/textView8" />

Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
Usman
  • 23
  • 1
  • 5
  • Try this http://stackoverflow.com/questions/3735095/how-can-i-avoid-illegalstateexception-scrollview-can-host-only-one-direct-chil – Maksim Feb 22 '15 at 11:23
  • this code generate compile time error unless you've closed ScrollView Tag also ScrollView can always get a one ViewGroup Like LinearLayout and ReleativeLayout as a child. – Arash GM Feb 22 '15 at 11:25
  • did you have code for hiding keyboard on touch on scrollview?, that was my case i stopped that and it worked – shareef Mar 19 '19 at 09:14

2 Answers2

1

This should help

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/ScrollView">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/RelativeLayout">

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="INTRODUCTION:"
            android:id="@+id/heading1"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:textAlignment="center"
            android:phoneNumber="false"
            android:textStyle="bold" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/Introduction"
            android:id="@+id/textView2"
            android:layout_below="@+id/heading1"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="10dp"
            android:layout_marginStart="10dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="HYDROCARBON:"
            android:id="@+id/textView3"
            android:layout_below="@+id/textView2"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:textStyle="bold" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/hydrocarbon"
            android:id="@+id/textView4"
            android:layout_below="@+id/textView3"
            android:layout_alignLeft="@+id/textView2"
            android:layout_alignStart="@+id/textView2" />

        <ImageView
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:id="@+id/imageView"
            android:layout_below="@+id/textView4"
            android:layout_centerHorizontal="true"
            android:src="@drawable/ethane" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:text="TYPES OF HYDROCARBON:"
            android:id="@+id/textView5"
            android:layout_below="@+id/imageView"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:textStyle="bold" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/types"
            android:id="@+id/textView6"
            android:layout_below="@+id/textView5"
            android:layout_alignLeft="@+id/textView4"
            android:layout_alignStart="@+id/textView4" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Alkane"
            android:id="@+id/textView7"
            android:layout_below="@+id/textView6"
            android:layout_alignLeft="@+id/textView6"
            android:layout_alignStart="@+id/textView6" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Alkene"
            android:id="@+id/textView8"
            android:layout_below="@+id/textView7"
            android:layout_alignLeft="@+id/textView7"
            android:layout_alignStart="@+id/textView7" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="Alkyne"
            android:id="@+id/textView9"
            android:layout_below="@+id/textView8"
            android:layout_alignLeft="@+id/textView8"
            android:layout_alignStart="@+id/textView8" />

        <Button
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="BACK"
            android:id="@+id/button2"
            android:onClick="mainPage"
            android:layout_below="@+id/textView9"
            android:layout_alignRight="@+id/textView8"
            android:layout_alignEnd="@+id/textView8" />

    </RelativeLayout>
</ScrollView>
Chipset
  • 51
  • 2
  • 10
  • Thanks .. this problem is solved but another problem is that the page of activity is full and i want to add more things in this activity .. the page which is shown in design is not scroll any more.. – Usman Feb 22 '15 at 19:32
  • If this problem is solved, please accept the correct answer. For the other problem, please open a new question if you're not able to find a solution to the problem. – Chipset May 15 '15 at 09:46
1

Scroll view tag can have only one child element Put your content of scroll view in linear layout.

<ScrollView>
<LinearLayout>
.......
.......
.....

</LinearLayout>
</ScrollView>
Fahim
  • 12,198
  • 5
  • 39
  • 57