解决异常Circular dependencies cannot exist in RelativeLayout

来源:互联网 发布:clean my mac 怎么样 编辑:程序博客网 时间:2024/05/01 07:37
今天碰到这个error:E/AndroidRuntime( 4657): Uncaught handler: thread main exiting due to uncaught e
xception
E/AndroidRuntime( 4657): java.lang.IllegalStateException: Circular dependencies
cannot exist in RelativeLayout
有点郁闷,我用的是skd1.5,在1.5的机器上(HTC G3)已经测试过了,没有问题的,但放在华为c8500(2.1update)上就报上面的错了,怎么回事呢?
根据提示判断应该是布局的原因,于是找到RelativeLayout的布局,找出最可疑的那个,注释后,不报错了。好就是他的原因,挨个看里面的元素,看属性,没错啊,后来发现,
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_alignParentRight="true">
<TextView android:id="@+id/titleName" android:text="首页"
android:textColor="@color/white" android:layout_toLeftOf="@+id/homeBtn"
android:layout_marginRight="2px"
android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<ImageButton android:id="@+id/homeBtn"
android:layout_toRightOf="@+id/titleName" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/main"
android:background="@null" android:layout_marginRight="10px">
</ImageButton>
</RelativeLayout>

后来改成:

<RelativeLayout android:layout_width="wrap_content" android:layout_marginRight="10px"
android:layout_height="wrap_content" android:layout_alignParentRight="true">
<TextView android:id="@+id/titleName" android:text="首页"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
<ImageButton android:id="@+id/homeBtn"
android:layout_marginLeft="2px" android:layout_marginTop="2px"
android:layout_toRightOf="@+id/titleName" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:src="@drawable/main"
android:background="@null" >
</ImageButton>
</RelativeLayout>


能看到区别吗?对就是在titleName中去掉了相对homeBtn的位置信息。再看看报错提示,人家说我在RelativeLayout中存在循环的相关,就是说的这个了。
不过1.5版本的不报错,这就是后续版本的改进吗?
0 0
原创粉丝点击