问题描述
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:id="@+id/text_view"
android:backgroind="@drawable/ic_launcher" />
<TextView
android:id="@+id/text_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
。机器人:ID
不能正常工作
根的观点是工作(@ + ID /相对)
。 TextView的提示类或接口预期
。
我尝试其他资源(绘制,布局)就可以了。只有在R档ID attr为不work.but根视图的是attr为正常。
The root view is work(@+id/relative)
. The TextView prompts "class' or 'interface' expected"
.I try other resource(drawable,layout) is ok. only id attr in R file is not work.but root view 's is attr is ok.
我搜索谷歌,但找不到答案。
I searched google but couldn't find an answer.
帮助!谢谢!
在这里谢谢回复的朋友的问题,我的第一个问题,英语也不好,非常感谢大家的耐心等待:)。我的previous AndroidStudio的版本是0.1.9,现在是0.2.10,错误之前做的项目,你不能运行该项目,但它仍然是在机器人:ID =@ + ID / ******
出现在红线下方不提示输入信息,但可以使项目时,您可以运行该项目。
Thank you for answering questions of friends, my first question here, English is not good, thank you very much for your patience:). My previous AndroidStudio version is 0.1.9, is now 0.2.10, make project before the error, you can not run the project, although it is still in the android: id =" @ + id / ****** "
appear below the red line is not prompted to enter information, but you can make project, you can run the project.
推荐答案
使用
android:id="@+id/text_view" // for textview 1
和
android:id="@+id/textview2" // // for textview 2
任何视图对象可具有与其相关联的一个整数ID,唯一地识别在树中的视角。当应用程序被编译时,这个ID被标记为一个整数,但是ID通常被分配布局XML文件作为字符串中的id属性。
Any View object may have an integer ID associated with it, to uniquely identify the View within the tree. When the application is compiled, this ID is referenced as an integer, but the ID is typically assigned in the layout XML file as a string, in the id attribute.
例如:
android:id="@+id/my_button"
该符号在字符串的开头(@)表示XML解析器解析应该和扩大ID字符串的其余部分,其标识为ID的资源。在加号(+)指这是必须被创建并添加到我们的资源(在R.java文件)的新资源名称
The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).
检查此链接。检查下ID的话题
Check this link. Check the topic under ID
编辑:
同样改变
android:backgroind="@drawable/ic_launcher" />
到
android:background="@drawable/ic_launcher" /> // typo error
这篇关于Android Studio中的XML文件@Id不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!