Reputation: 21
Using scrollView causes my application to crash. I need a scrollview as all of the content is not visible in the screen, it is down past the end of the screen. Here is my code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:isScrollContainer="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:text="RECORD MATCH DETAILS"
android:textSize="25dip"
android:textStyle="bold" />
<TextView
android:text="Home Team:"
android:textStyle="bold"/>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true" />
<TextView
android:text="Away Team:"
android:textStyle="bold"/>
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true" />
<TextView
android:text="Select Date:"
android:textStyle="bold"/>
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:text="Select Time:"
android:textStyle="bold"/>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
Any ideas? Thanks in advance!
Upvotes: 1
Views: 211
Reputation: 21
Got It!!
Thanks for all your help.
My linearlayout layout_height needed to be 'wrap_content'. I also entered the data in table format. Here is my new code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dip"
android:text="RECORD MATCH DETAILS"
android:textSize="25dip"
android:textStyle="bold" />
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView
android:text="Home Team:"
android:textStyle="bold"/>
</TableRow>
<TableRow>
<Spinner
android:id="@+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true" />
</TableRow>
<TableRow>
<TextView
android:text="Away Team:"
android:textStyle="bold"/>
</TableRow>
<TableRow>
<Spinner
android:id="@+id/spinner2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true" />
</TableRow>
<TableRow>
<TextView
android:text="Select Date:"
android:textStyle="bold"/>
</TableRow>
<TableRow>
<DatePicker
android:id="@+id/datePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow>
<TextView
android:text="Select Time:"
android:textStyle="bold"/>
</TableRow>
<TableRow>
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</TableRow>
<TableRow >
<Button
android:id="@+id/btnCreateMatch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dip"
android:layout_marginBottom="15dip"
android:textSize="20dp"
android:text="Create Match"/>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
Thanks again!
Upvotes: 0
Reputation: 39386
Your layout is invalid because your TextViews do not specify a layout_width and height. This is explained in the stacktrace from the crash of your app
Upvotes: 2