今天在练习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. cnb

    <style type="text/css"> .fieldset_s{border: 1px #dedede solid;padding: 19px; color: ...

  2. 【转】java中静态代码块的用法 static用法详解

    原文网址:http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796209.html (一)java 静态代码块 静态方法区别一般情况下,如 ...

  3. C# MVC模式下商品抽奖

    很久没有写博客,于是就把最近项目需求的一个抽奖功能给整理了下,语言表达能力不好,写的不好请勿吐槽,一笑而过就好.好了下面开始说说这个抽奖功能.因为涉及到公司的项目所以一些敏感的地方均已中文代替. 首先 ...

  4. 安装Intel CPU的Android模拟器

    1. 用Android SDK Manager安装Extras/Intel x86 Emulator Accelarator(HAXM) 2. 用Android SDK Manager安装Androi ...

  5. 性能测试vs负载测试vs压力测试-概念普及

    下面我们主要介绍性能测试.负载测试和压力测试. 效率作为ISO 9126内部和外部质量的重要质量属性之一,其含义是在规定条件下,相对于所用的资源的数量,软件产品可提供适当性能的能力.资源可能包括其他软 ...

  6. EF架构随心所欲打造属于你自己的DbModel【转】

    前言 我们都知道EF可以生成Dbmodel,系统生成的Model有时候并不是我们想要的,如何我们要生成自己的Model,那么久需要我们手动的去修改T4模版,T4是对“Text Template Tra ...

  7. 【CSS3】Advanced7:CSS Transitions

    1.animate parts of your design without the need for the likes of JavaScrip 2.allowing smooth animati ...

  8. 动态代理入门(jdk)

    动态代理就是aop的核心,动态代理简单的就是通过创建一个代理对象,然后把原来的方法增强.很抽象,例子是王道.jdk中提供了动态代理的实现,但是它是针对接口,如果要实现动态代理,需要被代理对象的接口.这 ...

  9. 五指CMS开发日志(一)

    开发了这么长时间,基本功能已经具备了.分享一下后台的界面吧.

  10. HDU 1166 敌兵布阵 线段树区间求和 更改

    水 #include<iostream> #include<string> #include<algorithm> #include<cstdlib> ...