Android 未找到与给定名称匹配的资源(位于';布局';处,带值';@id/right#item_menu#u fragment';) 我试图配置三个片段:一个左边有固定宽度,右边有一个固定宽度,中间一个占据所有剩余空间。我搜索了一个解决方案,并遵循了我在网上找到的建议,但是当我尝试运行应用程序时,我遇到了一个错误:
未找到与给定名称匹配的资源(在'layout\u toRightOf'处,值为'@id/right\u item\u menu\u fragment')。 如果我将RelativeLayout id='canvas\u fragment'移动到layout id='right\u item\u menu\u fragment'之后,则安装成功(无上述错误),但“canvas\u fragment”在屏幕上不可见 我搜索了这个错误,有不同的原因为什么它会发生,但没有一个适用于我的情况。很多人在使用Eclipse时都会犯这个错误,但我使用的是Android studio 如果有人能指出我做错了什么,我会非常感激你的帮助 以下是我的布局:Android 未找到与给定名称匹配的资源(位于';布局';处,带值';@id/right#item_menu#u fragment';) 我试图配置三个片段:一个左边有固定宽度,右边有一个固定宽度,中间一个占据所有剩余空间。我搜索了一个解决方案,并遵循了我在网上找到的建议,但是当我尝试运行应用程序时,我遇到了一个错误:,android,android-layout,Android,Android Layout,未找到与给定名称匹配的资源(在'layout\u toRightOf'处,值为'@id/right\u item\u menu\u fragment')。 如果我将RelativeLayout id='canvas\u fragment'移动到layout id='right\u item\u menu\u fragment'之后,则安装成功(无上述错误),但“canvas\u fragment”在屏幕上不可见 我搜索了这个错误,有不同的原因为什么它会发生,但没有一个适用于我的情况。很多人在使用
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/canvas_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/left_item_menu_fragment"
android:layout_width="@dimen/item_menu_width"
android:layout_height="match_parent"
android:layout_alignParentLeft = "true"
android:background="#cccccc">
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/canvas_fragment"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_toLeftOf = "@+id/left_item_menu_fragment"
android:layout_toRightOf = "@id/right_item_menu_fragment"
android:background="#000000" >
</RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/right_item_menu_fragment"
android:layout_width="@dimen/item_menu_width"
android:layout_height="match_parent"
android:layout_alignParentRight = "true"
android:background="#cccccc">
</RelativeLayout>
</RelativeLayout>
我以前遇到过这个问题,这似乎是一个前瞻性的参考问题。尝试按如下方式重新排列相关布局,以便最后定义中间部分
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/canvas_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/left_item_menu_fragment"
android:layout_width="@dimen/item_menu_width"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#cccccc">
</RelativeLayout>
<RelativeLayout
android:id="@+id/right_item_menu_fragment"
android:layout_width="@dimen/item_menu_width"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#cccccc">
</RelativeLayout>
<RelativeLayout
android:id="@+id/canvas_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
<!-- layout_toLeftOf and layout_toRightOf were backwards. This is correct.-->
android:layout_toLeftOf="@id/right_item_menu_fragment"
android:layout_toRightOf="@id/left_item_menu_fragment"
android:background="#000000"
android:orientation="vertical">
</RelativeLayout>
在id
前面添加一个+
。也就是说,“@+id/right\u item\u menu\u fragment”
。如果你的布局是那样的,那么这个ID还没有生成,+
就是这样做的。我试过了,屏幕上甚至没有显示“canvas_片段”。只有左边和右边的碎片。然而,我发现了如何使用权重来显示它。我将外部布局定义为android:weightSum=“10”,并为每个片段赋予相应的布局权重:1、9和1我刚刚注意到,画布片段
被布置在左侧项目菜单片段
的“左侧”和右侧项目菜单片段
的右侧,这是向后的。应将其布置在“右侧项目菜单”片段的“左侧”和左侧项目菜单片段的右侧。你同意吗?这很容易被忽略。谢谢,@Cheticamp,这就是画布碎片没有显示的原因。它正在工作。