现在的位置: 首页 > 综合 > 正文

android 的relativelayout 报错 No resource found that matches the given name

2013年08月12日 ⁄ 综合 ⁄ 共 1518字 ⁄ 字号 评论关闭
============================================================
博文原创,转载请声明出处
电子咖啡(原id蓝岩)
============================================================

android 的relativelayout 报错

error: Error: No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/
  main_auto_checkbox').

后来才发现是我在A中引用了B的id,但是B的id是在后面声明的,编译器是顺序执行的(在我看来),因此找不到,当我把B的声明放在A的前面,就ok了,

	<RelativeLayout android:orientation="horizontal"
				android:layout_width="wrap_content" android:layout_height="wrap_content"
				android:gravity="center">
				<TextView android:layout_width="wrap_content"
					android:layout_height="wrap_content" android:gravity="center"					
					android:layout_toLeftOf="@id/main_auto_checkbox" 	--这里错了,引用的id声明在后面,系统找不到
					android:text="自动修复" android:layout_centerVertical="true"/>
				<CheckBox android:id="@+id/main_auto_checkbox"
					android:layout_width="wrap_content" android:layout_height="wrap_content"
					android:layout_alignParentRight="true" android:layout_marginRight="3dip"/>
			</RelativeLayout>

,更换checkbox和textview的声明顺序,这个样子就对了

			<RelativeLayout android:orientation="horizontal"
				android:layout_width="wrap_content" android:layout_height="wrap_content"
				android:gravity="center">
				<CheckBox android:id="@+id/main_auto_checkbox"
					android:layout_width="wrap_content" android:layout_height="wrap_content"
					android:layout_alignParentRight="true" android:layout_marginRight="3dip"/>
				<TextView android:layout_width="wrap_content"
					android:layout_height="wrap_content" android:gravity="center"
					android:layout_toLeftOf="@id/main_auto_checkbox" 
					android:text="自动修复" android:layout_centerVertical="true"/>
			</RelativeLayout>


抱歉!评论已关闭.