首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

解决异常Circular dependencies cannot exist in RelativeLayout

今天碰到这个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版本的不报错,这就是后续版本的改进吗?

02

Android开发笔记(三十七)按钮类控件

Button是文本按钮(继承自TextView),而ImageButton是图像按钮(继承自ImageView)。两者之间的区别在于: 1、Button即可显示文本也可显示图形(通过设置背景图),而ImageButton只能显示图形不能显示文本; 2、Button可在文本周围区域显示小图,而ImageButton无法在某个区域显示小图; 3、ImageButton上的图像可按比例进行拉伸,而Button上的大图会拉伸变形(因为背景图无法按比例拉伸); 从上面可以看出,Button的适应面更广,所以实际开发中基本使用Button。 Button与ImageButton的单击方法是setOnClickListener,对应的监听器要实现接口View.OnClickListener。长按方法是setOnLongClickListener,对应的监听器要实现接口View.OnLongClickListener。下面是Button按键监听器的代码例子:

03

扫码

添加站长 进交流群

领取专属 10元无门槛券

手把手带您无忧上云

扫码加入开发者社群

相关资讯

热门标签

活动推荐

    运营活动

    活动名称
    广告关闭
    领券