【问题标题】:Layout causing App to crash布局导致 App 崩溃
【发布时间】:2014-03-10 18:01:55
【问题描述】:

所以我一直在尝试更改我的几个 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 中的按钮方式有关,所以我该如何解决这个问题?

提前谢谢你,

泰勒

【问题讨论】:

标签: android xml layout


【解决方案1】:
<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" 形成循环依赖关系。

【讨论】:

  • 谢谢,我摆脱了 android:layout_toLeftOf="@+id/ButtonAll" 和 android:layout_toLeftOf="@+id/ButtonBack" 但现在 ButtonOk 没有出现。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多