Reputation: 41
I have this xml code,I want to set a scroll view for these buttons.Can anybody help me? It is showing error when i set a scroll view inside the layout.The xml contain some buttons and textviews .Textviews and buttons are aligned horizontally inside a Linear Layout with vertical orientation.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.cozyne.toglebtn.MainActivity" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >
<LinearLayout
android:id="@+id/llTopBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#00ff00"
android:dividerPadding="22dip"
android:orientation="horizontal"
android:showDividers="middle" >
<TextView
android:id="@+id/textView1"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:text="12:00 AM" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="62dp"
android:text="ON" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#00ff00"
android:dividerPadding="22dip"
android:orientation="horizontal"
android:showDividers="middle" >
<TextView
android:id="@+id/textView3"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:text="12:00 AM"
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="62dp"
android:text="ON" />
</LinearLayout>
</ScrollView>
Upvotes: 0
Views: 3545
Reputation: 278
Try this simplest soultion:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Add up your Content -->
</LinearLayout>
</ScrollView>
Upvotes: 0
Reputation: 9870
The problem is that You have not ended up with the xml. You have to put the
</LinearLayout>
Tag at the end. You started with a LinearLayout as the parent container and put inside the scrollView. Then You put again a LinearLayout inside etc... . But at the end of Your xml, You don´t close the parent LinearLayout....
The second issue is, that You have more than one view inside the ScrollView. You have two LinearLayouts inside, just make one view inside a scrollView. It´s not allowed to put more than one inside scrollView...
and finally, like Rubén Jiménez said, You missed the tag at the end of Your textView. That edit is just for the sake of completeness...
Upvotes: 2
Reputation: 126
You also missed the "/>" at the final of the textView.
Change it for:
<TextView
android:id="@+id/textView3"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:text="12:00 AM" />
Upvotes: 1
Reputation: 5542
ScrollView can have only one direct child
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.cozyne.toglebtn.MainActivity" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical">
<LinearLayout
android:id="@+id/llTopBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#00ff00"
android:dividerPadding="22dip"
android:orientation="horizontal"
android:showDividers="middle" >
<TextView
android:id="@+id/textView1"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:text="12:00 AM" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="62dp"
android:text="ON" />
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#00ff00"
android:dividerPadding="22dip"
android:orientation="horizontal"
android:showDividers="middle" >
<TextView
android:id="@+id/textView3"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:text="12:00 AM" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="62dp"
android:text="ON" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Upvotes: 2