2013-01-22 55 views
1

希望這是一個簡單的問題。Scrollview XML佈局問題

我有一個使用滾動視圖的佈局。這是沒有問題的,直到我想把一個圖像和textview放在它的上面,然後在我的edittexts下滾動視圖。

目前,我得到了以下錯誤:

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. 

我曾試圖改變滾動視圖寬度屬性(我相信,錯誤指向太),沒有運氣。

這是我的XML。任何人都可以看到我做錯了什麼?:

<?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> 

編輯:

enter image description here

回答

2

只能設置一個子佈局的滾動型。我不知道爲什麼它會告訴你,你沒有設置android:layout_width屬性,但你的問題是你的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> 
+0

@Ahmed謝謝你的回覆。我添加了linearlayout和我的圖像和textview顯示,但現在線性佈局中的所有內容都不顯示。 – user1352057

+0

您是否將方向設置爲垂直?滾動工作? – Ahmad

+0

@Ahmed是的線性佈局是垂直的。我添加了一張照片,顯示它現在的樣子。滾動視圖是完全空白的。 – user1352057