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

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

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

出现错误的代码:

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. tools:context="com.why.practice.viewpagerfragment1.MainActivity" >
  6.  
  7. <FrameLayout
  8. android:id="@+id/fragmentLayout"
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:layout_alignParentTop="true"
  12. android:layout_above="@id/btnLayout"
  13. android:layout_centerHorizontal="true">
  14. </FrameLayout>
  15.  
  16. <LinearLayout
  17. android:id="@+id/btnLayout"
  18. android:layout_width="match_parent"
  19. android:layout_height="wrap_content"
  20. android:layout_alignParentBottom="true"
  21. android:layout_centerHorizontal="true">
  22.  
  23. <Button
  24. android:id="@+id/btn_one"
  25. android:layout_width="0.0dp"
  26. android:layout_height="match_parent"
  27. android:layout_weight="1"
  28. android:layout_margin="5dp"
  29. android:text="@string/btn_oneText"
  30. android:background="#009eff"
  31. android:textColor="#fff"
  32. style="?android:attr/buttonBarButtonStyle"
  33. />
  34.  
  35. <Button
  36. android:id="@+id/btn_two"
  37. android:layout_width="0.0dp"
  38. android:layout_height="match_parent"
  39. android:layout_weight="1"
  40. android:layout_margin="5dp"
  41. android:text="@string/btn_twoText"
  42. android:background="#009eff"
  43. android:textColor="#fff"
  44. style="?android:attr/buttonBarButtonStyle"
  45. />
  46. <Button
  47. android:id="@+id/btn_three"
  48. android:layout_width="0.0dp"
  49. android:layout_height="match_parent"
  50. android:layout_weight="1"
  51. android:layout_margin="5dp"
  52. android:text="@string/btn_threeText"
  53. android:background="#009eff"
  54. android:textColor="#fff"
  55. style="?android:attr/buttonBarButtonStyle"
  56. />
  57.  
  58. </LinearLayout>
  59.  
  60. </RelativeLayout>

正确的代码:

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. tools:context="com.why.practice.viewpagerfragment1.MainActivity" >
  6.  
  7. <LinearLayout
  8. android:id="@+id/btnLayout"
  9. android:layout_width="match_parent"
  10. android:layout_height="wrap_content"
  11. android:layout_alignParentBottom="true"
  12. android:layout_centerHorizontal="true">
  13.  
  14. <Button
  15. android:id="@+id/btn_one"
  16. android:layout_width="0.0dp"
  17. android:layout_height="match_parent"
  18. android:layout_weight="1"
  19. android:layout_margin="5dp"
  20. android:text="@string/btn_oneText"
  21. android:background="#009eff"
  22. android:textColor="#fff"
  23. style="?android:attr/buttonBarButtonStyle"
  24. />
  25.  
  26. <Button
  27. android:id="@+id/btn_two"
  28. android:layout_width="0.0dp"
  29. android:layout_height="match_parent"
  30. android:layout_weight="1"
  31. android:layout_margin="5dp"
  32. android:text="@string/btn_twoText"
  33. android:background="#009eff"
  34. android:textColor="#fff"
  35. style="?android:attr/buttonBarButtonStyle"
  36. />
  37. <Button
  38. android:id="@+id/btn_three"
  39. android:layout_width="0.0dp"
  40. android:layout_height="match_parent"
  41. android:layout_weight="1"
  42. android:layout_margin="5dp"
  43. android:text="@string/btn_threeText"
  44. android:background="#009eff"
  45. android:textColor="#fff"
  46. style="?android:attr/buttonBarButtonStyle"
  47. />
  48.  
  49. </LinearLayout>
  50.  
  51. <FrameLayout
  52. android:id="@+id/fragmentLayout"
  53. android:layout_width="match_parent"
  54. android:layout_height="match_parent"
  55. android:layout_alignParentTop="true"
  56. android:layout_above="@id/btnLayout"
  57. android:layout_centerHorizontal="true">
  58. </FrameLayout>
  59.  
  60. </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. BZOJ_1618_ [Usaco2008_Nov]_Buying_Hay_购买干草(动态规划,完全背包)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1618 有n种物品,每种物品有价值和重量,可以无限拿.现在要满足价值之和大于等于h,问最小重量. ...

  2. LoadLibraryEx及发回hmodule的一些细节

    LoadLibraryEx可以配合 DONT_RESOLVE_DLL_REFERENCES LOAD_LIBRARY_AS_DATAFILE LOAD_LIBRARY_AS_DATAFILE_EXCL ...

  3. How to Customize Server Header using NginX headers-more module

    http://wiki.nginx.org/HttpHeadersMoreModule#Version headers_more When you are browsing a website, yo ...

  4. Azure Backup 入门

    Viswanath Tata 云 + Enterprise项目经理 Azure Backup是一款允许客户将数据备份到 Azure的强大工具.请参阅这篇文章,快速了解 Azure Backup.我 ...

  5. 编写一个jsp页面,输出九九乘法表。

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"% ...

  6. testng 注解

    testng.xml suite(套件):  由一个或多个测试组成 test(测试):  由一个或多个类组成 class(类):  一个或多个方法组成 @BeforeSuite: 在某个测试套件开始之 ...

  7. html总结----------------------看这个就够了

    HTML是我们学习Javaweb的第一步 很好地掌握门课是非常有必要的!下面就是我在听资深老师讲课的笔记!个人觉得非常不错!希望可以帮助到那些在学习javaweb路上的 朋友们!从今天 陆续的整理这门 ...

  8. Sublime Text 2使用心得

    一个比较详细的文章:http://www.cnblogs.com/figure9/p/sublime-text-complete-guide.html 一. 前言 作为一个前端,有一款好的开发利器是必 ...

  9. HIbernate学习笔记(一) 了解hibernate并搭建环境建立第一个hello world程序

    Hibernate是一个开放源代码的ORM(对象关系映射)框架,它对JDBC进行了轻量级的封装,Java程序员可以使用面向对象的编程思维来操纵数据库,它通过对象属性和数据库表字段之间的映射关系,将对象 ...

  10. HW2.15

    public class Solution { public static void main(String[] args) { double rate = 0.05; double balance ...