今天在练习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. xfce terminal tab被解释为super+tab的bug

    https://bugzilla.xfce.org/show_bug.cgi?id=10760 解决方法 Every few weeks the tab key stops working in th ...

  2. c语言时间库函数#include<time.h>

    日期与时间函数<time.h> 头文件<time.h>中说明了一些用于处理日期和时间的类型和函数.其中的一部分函数用于处理当地时间,因为时区等原因,当地时间与日历时间可能不相同 ...

  3. 安卓使用WIFI调试程序

    不知怎么回事,USB老是掉,真心烦.于是想着用WIFI可不可以调试呢,去百度一搜,果然可以.下面我说一下我的方案. 1.使用APWIFI创建WIFI热点,用安卓手机连接该热点,试试手机可以上网不. 2 ...

  4. STL总结之bitset

    STL的bitset是一个对位进行存储和操作的容器,可以轻松对bit位进行访问.   bitset的模板声明如下: template<size_t _Bits> class bitset; ...

  5. Selenium 实现联想下拉框

    直接在文本框输入字符,并不能实现联想下拉框, 第一种方式:强制执行js driver.FindElement(By.Id("top_search_input")).SendKeys ...

  6. 独立线程中实现QT GUI

    在网上搜集的资料: http://www.qtcentre.org/threads/16552-Starting-QT-GUI-in-a-seperate-Threadhttp://stackover ...

  7. 密码加密md5和sha

    package cn.springmvc.util;import java.security.MessageDigest;import java.security.NoSuchAlgorithmExc ...

  8. FIRST集和FOLLOW集

    省略号代表其他相关产生式得出的终结符号,一开始的时候,省略号里面是没有的   求FIRST集 情况壹  如果A只在→的右边出现,那么FIRST(A)={A},例子M→α,FIRST(α)={α} 情况 ...

  9. LCD platform_device(s5pv210)

    devs.c:   static struct resource s3cfb_resource[] = { [0] = { .start= S5P_PA_LCD, .end= S5P_PA_LCD + ...

  10. bzoj 1879 [Sdoi2009]Bill的挑战(状压DP)

    Description  Input 本题包含多组数据. 第一行:一个整数T,表示数据的个数. 对于每组数据: 第一行:两个整数,N和K(含义如题目表述). 接下来N行:每行一个字符串. Output ...