`

解决 No resource found that matches the given name (at 'layout_above' with value '@id/button3').

 
阅读更多

今天继续学习郭少的<<第一行代码>>,读到3.3.2相对布局这一章(P102页),根据书上的实例,运行以后在控制台显示了,

Information:Gradle tasks [:app:assembleDebug]
C:\Users\Administrator\AndroidStudioProjects\UILayoutTest\app\src\main\res\layout\activity_main.xml
Error:(10, 31) No resource found that matches the given name (at 'layout_above' with value '@id/button3').
Error:(11, 34) No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/button3').
Error:(17, 31) No resource found that matches the given name (at 'layout_above' with value '@id/button3').
Error:(18, 35) No resource found that matches the given name (at 'layout_toRightOf' with value '@id/button3').

 

好你是说没有找到与‘@id/button3‘匹配的名字的资源,怎么回事呢,仔细看了一下activity_main.xml,发现了问题

 

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button3"
android:layout_toLeftOf="@id/button3"
android:text="Button 1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/button3"
android:layout_toRightOf="@id/button3"
android:text="Button 2" />
<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:text="Button 3" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button3"
android:layout_toLeftOf="@id/button3"
android:text="Button 4" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button3"
android:layout_toRightOf="@id/button3"
android:text="Button 5" />

 

最后读到第103页,上面清楚的写到。注意,当一个控件去引用另一个控件的id时,该控件一定要定义在引用控件的后面,不然会出现找不到id的情况将button3写到中间了,将button3的位置放到button1上面就行了,期待大家不要犯同样的错误!

 

分享到:
评论

相关推荐

    apktool_AndResGuard:修复apktool打包出现No resource found...

    No resource found that matches the given name..... ....... 使用apktool-2.0.3也可以回编译,但是比如微信回编译后会增加到110M左右,很不友好。 而使用apktool-2.3.2和原包大小一样,65M左右。 基于apktool

    微信开放平台之网站授权微信登录功能

    2 微信官方教程:https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419316505&token=&lang=zh_CN 3.pc页面显示 4. 通过官方提供的文档,我们可以看出一共分...

    lichee_20170502_1607_全志R16的linux系统编译需要改动的文件_使用parrotv1.1的内核_没有外层目录.7z

    rootroot@cm-System-Product-Name:/home/wwt/linux_r16/lichee$ ./build.sh config Welcome to mkscript setup progress All available chips: 0. sun8iw5p1 Choice: 0 All available platforms: 0. android 1. ...

    lunch_cb5801_r58_20160907.7z

    ./configs/media_profiles.xml: not perform any checks at all. 不用修改 ./vendorsetup.sh:add_lunch_combo octopus_perf-eng ./vendorsetup.sh:add_lunch_combo octopus_perf-user 直接用cb5801搜索替换perf...

    lunch_r58_20160906.7z

    ./configs/media_profiles.xml: not perform any checks at all. 不用修改 ./vendorsetup.sh:add_lunch_combo octopus_perf-eng ./vendorsetup.sh:add_lunch_combo octopus_perf-user 直接用cb5801搜索替换perf...

    signal PYQT5

    onNewSelection@resource://devtools/client/inspector/inspector.js:1324:5 emit@resource://devtools/shared/event-emitter.js:178:15 emit@resource://devtools/shared/event-emitter.js:255:5 setNodeFront@...

    Android代码-高仿全民直播

    KingTV 本App 采用 MVP RXJava ...Name: Jenly Email: jenly1314@gmail.com / jenly1314@vip.qq.com CSDN: http://blog.csdn.net/jenly121 Github: https://github.com/jenly1314 微信公众号: 加入QQ群: 2086

    linux全志R16的linux系统编译的资料_20170502_1655.7z

    rootroot@cm-System-Product-Name:/home/wwt/linux_r16/lichee$ ./build.sh config Welcome to mkscript setup progress All available chips: 0. sun8iw5p1 Choice: 0 All available platforms: 0. android 1. ...

    android 百度地图 定位示例

    final Button btn_location = (Button) findViewById(R.id.btn_location); btn_location.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-...

    resource-race:NPM软件包可在组中找到最快的资源

    \\__.-"-._____ \\__.-"-...npm install resource-race 使用 import race from 'resource-race' ; const urls = [ 'https://cdn1.com/img.png' , 'https://cdn2.com/img.png' , 'https://cdn3.com/img.png' ] ; race

    android tools 29.02

    android tools 29.02

    pcf8563_i2c1_r8_ruoge_ov2640通过给RTC驱动增加设备节点读取秒钟成功+直接读取I2C1获取秒钟值20160626_2201.7z

    lrwxrwxrwx root root 1970-01-02 10:18 driver -&gt; ../../../../../bus/i2c/drivers/pcf8563 -r--r--r-- root root 4096 1970-01-02 10:18 modalias -r--r--r-- root root 4096 1970-01-02 10:18 name drwxr-xr-x ...

    andoid的man

    - error: Error: No resource found that matches the given name (at 'icon' with value '@drawable/icon'). - Should explicitly set android:allowBackup to true or false (it's true by default, and ...

    微信小程序npm引入vant-weapp的踩坑记录

    主要给大家介绍了关于微信小程序npm引入vant-weapp的踩坑记录,文中通过示例代码介绍的非常详细,对大家学习或者使用微信小程序具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧

    RunAsTI-master.zip

    The curious ones might notice that RunFromToken is attached as a resource. Have added the original source of RunFromToken as the exe's must be present in current directory when building RunAsTi. ...

    Rhino5_Python_Primer.pdf

    The RhinoPython community is very active and offers a wonderful resource for posting questions/answers and fi nding help on just about anything!: http://python.rhino3d.com/forums/ General References ...

    Resource ‘taggers/averaged_perceptron_tagger/averaged_perceptron _tagger.pickle’ not found.

    错误如下: LookupError: ********************************************************************** Resource 'taggers/averaged_... obtain the resource: &gt;&gt;&gt; nltk.download() Searched in: - 'C:\\Users\\Dr

    S60_Platform_Power_and_Resource_Management_Example_v2_1_en.zip

    how to implement some of the power and resource management principles that have been discussed in the document S60 Platform: Effective Power and Resource Management (available at ...

    exercise1 答案

    Note that with the URLs for #6 and #7, you should include a list of five things that make the Web pages well-designed and poorly-designed, respectively. Description - Part B Pick one of the topics ...

    rsh软件(LoadRunner监控Linux)

    Ensure that the machine can be connected and that it runs the rstat daemon (use rpcinfo utility for this verification). Detailed error: RPC: Failed to create RPC client.  RPC-TCP: Failed to ...

Global site tag (gtag.js) - Google Analytics