Reputation: 21
I'm newbie in android programming and I have a problem with "A scrollview can have only one child" what's wrong with my script ? I want to know if you have to take ScroolView ? Or how do I fix this problem ? Anyone can edit the scrpt correctly ?
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="-1"
android:layout_height="-1">
<LinearLayout
android:orientation="1"
android:layout_width="-1"
android:layout_height="-1">
<LinearLayout
android:orientation="1"
android:layout_width="-1"
android:layout_height="-1"
android:layout_marginLeft="12800"
android:layout_marginTop="2560">
<TextView
android:textColor="-1"
android:layout_width="-2"
android:layout_height="-2"
android:text="2131034150"/>
<Spinner
android:id="2131165208"
android:layout_width="94720"
android:layout_height="-2"
android:drawSelectorOnTop="-1"
android:prompt="2131034149"/>
<TextView
android:textColor="-1"
android:layout_width="-2"
android:layout_height="-2"
android:text="2131034143"/>
<EditText
android:id="2131165202"
android:layout_width="-2"
android:layout_height="-2"
android:maxLines="1"
android:width="94721"
android:maxLength="50"/>
<TextView
android:textColor="-1"
android:layout_width="-2"
android:layout_height="-2"
android:text="2131034144"/>
<EditText
android:id="2131165203"
android:layout_width="-2"
android:layout_height="-2"
android:maxLines="1"
android:width="94721"
android:password="-1"
android:maxLength="30"/>
</LinearLayout>
<LinearLayout
android:layout_gravity="3"
android:orientation="0"
android:paddingLeft="58881"
android:paddingBottom="5121"
android:layout_width="-2"
android:layout_height="-2">
<Button
android:id="2131165204"
android:layout_width="-2"
android:layout_height="-2"
android:text="2131034145"
android:width="35841"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
Upvotes: 2
Views: 3126
Reputation: 6736
first of all -1 -2 etc are invalid values for height and width of views and layouts.
The problem is self-described; a ScrollView
can't have more than 1 View
inside it.
Put all your views inside the root LinearLayout
Upvotes: 1
Reputation: 23
scrollView is not a layout. it is just a container that you can define your layout inside it. so you must define your layout in the scrollView; then add anything you need to the layout. so the views are grandchild of the scroll
your code should be like this
Upvotes: 0
Reputation: 1435
Yes it is true in android applications when you are designing a layout you can have only a single child of the ScrollView. and to solve this problem You have to make a as the child of that and all the other views and widgets will be inside the like the following code
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- all other childs (more than one) can be placed here -->
</Linearlayout>
</ScrollView>
Upvotes: 0
Reputation: 28823
Error is self explanatory.
A scrollview can have only one direct child.
So make a container layout, which contains all your children. And place that container layout inside a scrollview.
Example hierarchy:
<ScrollView>
<LinearLayout> <!-- new container layout-->
<!-- all your children layouts, views -->
</LinearLayou>
</ScrollView>
Upvotes: 5