No resource found that matches the given name (at 'layout_constraintRight_toLeftOf' w

来源:互联网 发布:手机号归属地 数据库 编辑:程序博客网 时间:2024/06/03 11:34

1.错误出现

Error:(29, 46) No resource found that matches the given name (at ‘layout_constraintRight_toLeftOf’ with value ‘@id/button_send’).

大致翻译:匹配名称的资源没有发现


<?xml version="1.0" encoding="utf-8"?><!--  Copyright (C) 2017 haomengjie  Licensed under the Apache License, Version 2.0 (the "License");  you may not use this file except in compliance with the License.  You may obtain a copy of the License at       http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software  distributed under the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and  limitations under the License.  --><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="match_parent">    <EditText        android:id="@+id/edit_message"        android:layout_width="0dp"        android:layout_height="wrap_content"        android:layout_marginLeft="16dp"        android:layout_marginTop="16dp"        android:hint="@string/edit_message"        app:layout_constraintLeft_toLeftOf="parent"        app:layout_constraintRight_toLeftOf="@id/button_send"        app:layout_constraintTop_toTopOf="parent" />    <Button        android:id="@+id/button_send"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_marginRight="0dp"        android:text="@string/button_send"        app:layout_constraintBaseline_toBaselineOf="@id/edit_message"        app:layout_constraintRight_toRightOf="parent" /></android.support.constraint.ConstraintLayout>

双击错误信息,可以定位到错误 代码行

    app:layout_constraintRight_toLeftOf="@id/button_send"

android ui呢,为了方便视图与逻辑分离,故使用xml布局

xml的话,就是android解析xml布局(顺序解析),再进行渲染

@id/button_send,意为使用一个已经存在的控件id,

从代码来看,button_send没有被解析,就被使用了,

这就造成了错误。


2. 解决问题

使用时全部替换成@+id(@id ==》 @+id)


@id 和 @+id 区别
https://stackoverflow.com/questions/5025910/difference-between-id-and-id-in-android

Android@id和@+id区别
http://blog.sina.com.cn/s/blog_6f5641ac0101b7vq.html


阅读全文
0 0
原创粉丝点击