2014-02-12 190 views
1

所以我一直在嘗試改變我的幾個xml中的佈局,但由於某種原因,當我改變這個崩潰的應用程序。新的佈局看起來像:佈局導致應用程序崩潰

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:background="@drawable/gradient_bg" > 
<RelativeLayout 
android:id="@+id/header" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentTop="true" 
android:gravity="center" > 

</RelativeLayout> 
<!-- Footer aligned to bottom --> 
<RelativeLayout 
android:id="@+id/footer" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_alignParentBottom="true"> 
<Button 
    android:id="@+id/ButtonOK" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_toLeftOf="@+id/ButtonAll" 
    android:text="Go" 
    style="@style/btnStyleBreakerBay"/> 
    <Button 
    android:id="@+id/ButtonAll" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="See All" 
    android:layout_toRightOf="@+id/ButtonOK" 
    android:layout_toLeftOf="@+id/ButtonBack" 
    style="@style/btnStyleBreakerBay"/> 
    <Button 
    android:id="@+id/ButtonBack" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="Back" 
    android:layout_toRightOf="@+id/ButtonAll" 
    style="@style/btnStyleBreakerBay"/> 
</RelativeLayout> 
<ScrollView 
android:id="@+id/scrollableContents" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:layout_above="@id/footer" 
android:layout_below="@id/header" > 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    > 
<TextView android:id="@+id/typeEvent" 
android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Type of Event:" 
    android:visibility="gone" 
    style="@style/black_text"/> 

     <Spinner 
    android:id="@+id/spinner_search_event" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/event_search_arrays" 
    android:prompt="@string/event_prompt" 
    android:visibility="gone"  
    android:popupBackground="#31535c"/> 

<!-- Name Label --> 
<TextView android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Type of Pavement:" 
    style="@style/black_text"/> 

     <Spinner 
    android:id="@+id/spinner_search_pavement" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/pave_search_arrays" 
    android:prompt="@string/pavement_prompt" 
    android:popupBackground="#31535c" /> 

     <!-- Name Label --> 
<TextView android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Amount of Traffic:" 
    style="@style/black_text"/> 
     <Spinner 
    android:id="@+id/spinner_search_traffic" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/traffic_search_arrays" 
    android:prompt="@string/traffic_prompt" 
    android:popupBackground="#31535c"/> 

     <!-- Name Label --> 
<TextView android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Type of Environment:" 
    style="@style/black_text"/> 
     <Spinner 
    android:id="@+id/spinner_search_enviro" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/enviro_search_arrays" 
    android:prompt="@string/enviro_prompt" 
    android:popupBackground="#31535c"/> 

     <TextView android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Max Miles away from you:" 
    style="@style/black_text"/> 
     <Spinner 
    android:id="@+id/spinner_dist" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:entries="@array/dist_arrays" 
    android:prompt="@string/dist_prompt" 
    android:popupBackground="#31535c"/> 
     </LinearLayout> 

</ScrollView> 
</RelativeLayout> 

現在logcat的說,這是因爲崩潰:

02-12 06:58:05.351: E/AndroidRuntime(2367): java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout 

和一對夫婦更紅線,但我認爲這是最主要的。現在我猜這與我在@ + id/footer中的按鈕有關,所以我該如何解決這個問題?

謝謝你在前進,

泰勒

+0

爲了清楚你可以檢查我的答案在這裏http://stackoverflow.com/a/11669528/1457952 – Shrikant

回答

5
<Button 
    android:id="@+id/ButtonOK" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_toLeftOf="@+id/ButtonAll" 
    android:text="Go" 
    style="@style/btnStyleBreakerBay"/> 
    <Button 
    android:id="@+id/ButtonAll" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="See All" 
    android:layout_toRightOf="@+id/ButtonOK" 
    android:layout_toLeftOf="@+id/ButtonBack" 
    style="@style/btnStyleBreakerBay"/> 

android:layout_toLeftOf="@+id/ButtonAll"android:layout_toRightOf="@+id/ButtonOK"使循環依賴。

+0

謝謝,我擺脫了android:layout_toLeftOf =「@ + id/ButtonAll」和android:layout_toLeftOf = 「@ + id/ButtonBack」,但現在ButtonOk不顯示。 – TylerM