1

Hoping this is a simple one.

I have a layout that uses a scrollview. This was fine until I wanted to put an image and textview above it then have the scrollview with my edittexts below it.

At the moment I'm getting the following errors:

01-22 20:13:32.228: E/AndroidRuntime(275): FATAL EXCEPTION: main
01-22 20:13:32.228: E/AndroidRuntime(275): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.flybase2/com.example.flybase2.addAppointment}: java.lang.RuntimeException: Binary XML file line #26: You must supply a layout_width attribute.

I have tried to change the scroll views width attribute (which i believe that error is pointing too) with no luck.

Here's my XML. Can anyone see what I'm doing wrong?:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="84dp"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imgLink"
        android:layout_width="78dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:src="@drawable/viewcon" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:gravity="center"
        android:text="Appointments"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="35sp" />
</LinearLayout>

\\ERROR: On width attribute
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/inputAppName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Appointment Type:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

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

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Appointment Time:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

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

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Appointment Time:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

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

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Comments:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/inputAppCom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />

<TextView
    android:id="@+id/textView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Set Appointment Date Alarm:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<ToggleButton
    android:id="@+id/toggleButton1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="ToggleButton"
    android:textOff="Alarm Off"
    android:textOn="Alarm On" />

<TextView
    android:id="@+id/textView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Appointment"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
    android:id="@+id/btnAddAppointment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Add" />

</ScrollView>
</LinearLayout>

EDIT:

enter image description here

0

1 Answer 1

2

You can only set one child layout to a ScrollView. I don't know why it's showing you that you didn't set android:layout_width attribute, but your problem is definitely that you have multiple child views in your ScrollView.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="84dp"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/imgLink"
        android:layout_width="78dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:src="@drawable/viewcon" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="75dp"
        android:gravity="center"
        android:text="Appointments"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="35sp" />
</LinearLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >


<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Name:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/inputAppName"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Appointment Type:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

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

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Appointment Time:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

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

<TextView
    android:id="@+id/textView4"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Appointment Time:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

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

<TextView
    android:id="@+id/textView5"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Comments:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
    android:id="@+id/inputAppCom"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" />

<TextView
    android:id="@+id/textView6"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Set Appointment Date Alarm:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<ToggleButton
    android:id="@+id/toggleButton1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="ToggleButton"
    android:textOff="Alarm Off"
    android:textOn="Alarm On" />

<TextView
    android:id="@+id/textView7"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Add Appointment"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
    android:id="@+id/btnAddAppointment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Add" />

 </LinearLayout>
 </ScrollView>
 </LinearLayout>
Sign up to request clarification or add additional context in comments.

6 Comments

@Ahmed Thanks for your reply. I have added the linearlayout and my image and textview show, but now everything within the linear layout does not show.
Did you set the orientation to vertical? Does the scrolling work?
@Ahmed Yes the linear layout is in a vertical orientation. I have added a picture showing what it looks like now. The scrollview is completely blank.
You did not set the orientation of your parent LinearLayout. Set it to vertical and it should work
@user1352057 set your main layout to vertical as well. it should help.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.