今天在练习fragment碎片的时候,进行界面布局的时候出现了这个问题。

后来解决后发现原因很简单:就是因为在布局xml文件中,引用ID和声明ID的顺序必须保证声明在前,引用在后。和布局的顺序无关。

【声明ID——android:id="@+id/btnLayout"。引用ID——android:layout_above="@id/btnLayout"】

出现错误的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.why.practice.viewpagerfragment1.MainActivity" > <FrameLayout
android:id="@+id/fragmentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="@id/btnLayout"
android:layout_centerHorizontal="true">
</FrameLayout> <LinearLayout
android:id="@+id/btnLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"> <Button
android:id="@+id/btn_one"
android:layout_width="0.0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:text="@string/btn_oneText"
android:background="#009eff"
android:textColor="#fff"
style="?android:attr/buttonBarButtonStyle"
/> <Button
android:id="@+id/btn_two"
android:layout_width="0.0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:text="@string/btn_twoText"
android:background="#009eff"
android:textColor="#fff"
style="?android:attr/buttonBarButtonStyle"
/>
<Button
android:id="@+id/btn_three"
android:layout_width="0.0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:text="@string/btn_threeText"
android:background="#009eff"
android:textColor="#fff"
style="?android:attr/buttonBarButtonStyle"
/> </LinearLayout> </RelativeLayout>

正确的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.why.practice.viewpagerfragment1.MainActivity" > <LinearLayout
android:id="@+id/btnLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"> <Button
android:id="@+id/btn_one"
android:layout_width="0.0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:text="@string/btn_oneText"
android:background="#009eff"
android:textColor="#fff"
style="?android:attr/buttonBarButtonStyle"
/> <Button
android:id="@+id/btn_two"
android:layout_width="0.0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:text="@string/btn_twoText"
android:background="#009eff"
android:textColor="#fff"
style="?android:attr/buttonBarButtonStyle"
/>
<Button
android:id="@+id/btn_three"
android:layout_width="0.0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_margin="5dp"
android:text="@string/btn_threeText"
android:background="#009eff"
android:textColor="#fff"
style="?android:attr/buttonBarButtonStyle"
/> </LinearLayout> <FrameLayout
android:id="@+id/fragmentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="@id/btnLayout"
android:layout_centerHorizontal="true">
</FrameLayout> </RelativeLayout>

error: Error: No resource found that matches the given name (at 'layout_above' with value '@id/btnLayout').的更多相关文章

  1. error:No resource found that matches the given name 'Theme.AppCompat.Light'

    一.stsckoverflow http://stackoverflow.com/questions/17870881/cant-find-theme-appcompat-light-for-new- ...

  2. android中出现Error retrieving parent for item: No resource found that matches the Theme.AppCompat.Light

    styles.xml中<style name="AppBaseTheme" parent="Theme.AppCompat.Light">提示如下错 ...

  3. error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.

    error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCom ...

  4. 【android】新手容易遇到的[error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'.]Theme出错的问题

    一.概述 近期刚接手了一个项目,开发工具为eclipse,由于版本较低,且考虑到如果转android studio项目的话,会其他人的维护带来困难,所以想着还是维护项目原来的开发环境吧. 但是导入项目 ...

  5. eclipse新建项目,报错“Error: workspace\appcompat_v7\res\values-v21\styles_base.xml No resource found that matches the given name”

    新建项目报错,不知道为什么,以前从未出现过的错误,把sdk更新之后,出现莫名错误,自己也是一知半解,在网上找了好久的错误,终于在一个english网站找到了解决方法,soga,从未觉得english如 ...

  6. error: Error retrieving parent for item: No resource found that matches the given name &#39;Theme.AppCompat.Light&#39;.,appcompatv7

    error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCom ...

  7. 【转】eclipse新建项目,报错“Error: workspace\appcompat_v7\res\values-v21\styles_base.xml No resource found that matches the given name”

    原文网址:http://www.cnblogs.com/mbp-study/p/5268478.html 新建项目报错,不知道为什么,以前从未出现过的错误,把sdk更新之后,出现莫名错误,自己也是一知 ...

  8. error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.

    引用appcompat 类库提示 error: Error retrieving parent for item: No resource found that  matches the given ...

  9. Error: No resource found that matches the given name (at 'icon' with value '@mipmap/Icon')

    问题: error: Error: No resource found that matches the given name (at 'icon' with value '@mipmap/Icon' ...

随机推荐

  1. Linux -- Ubuntu搭建java开发环境

    Steps 1 Check to see if your Ubuntu Linux operating system architecture is 32-bit or 64-bit, open up ...

  2. MFC窗口重绘

    Invalidate()与 UpdateAllViews()有什么分别 Invalidate()是让程序重画窗口. UpdateAllViews()是在DOC/VIEW结构中, 当一个视图的数据改变后 ...

  3. apache开源项目--CouchDB

    Apache CouchDB 是一个面向文档的数据库管理系统.它提供以 JSON 作为数据格式的 REST 接口来对其进行操作,并可以通过视图来操纵文档的组织和呈现. CouchDB 是 Apache ...

  4. java中通过类名实例化类

    String className ="test.Test1"; Class clazz; try { clazz = Class.forName(className); Test1 ...

  5. eight - zoj 1217 poj 1077

    学习了多位大牛的方法,看看到底能把时耗降到多少? A* // zojfulltest: 30000ms # include <stdio.h> # include <ctype.h& ...

  6. FZU 2237 中位数 主席树 树上k大

    #include <cstdio> #include <cstring> #include <queue> #include <set> #includ ...

  7. Nginx配置中运行与启动的详细介绍【转】

    原文:http://developer.51cto.com/art/201003/190944.htm 我们在进行Nginx配置的时候会出现很多不明白的地方,其实有些时候只要换一个思维的方式就能找多你 ...

  8. JS实现的一个验证码,可以在前端验证后在提交action

    js实现的一个验证码功能,可以在前端判断验证码输入是否正确 输入的邮箱格式是否正确 验证成功后才提交action到后台 <!DOCTYPE html PUBLIC "-//W3C//D ...

  9. android onTouch()与onTouchEvent()的区别

    1.onTouch方法: onTouch方法是View的 OnTouchListener借口中定义的方法.当一个View绑定了OnTouchLister后,当有touch事件触发时,就会调用onTou ...

  10. 2015 CCPC D- Pick The Sticks(UESTC 1218) (01背包变形)

    http://acm.uestc.edu.cn/#/problem/show/1218 既然二维dp表示不了,就加一维表示是否在边界放置,放置一个,两个.有一个trick就是如果只放一根,那么多长都可 ...