Error:(86, 50) No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/tvComment')

Error:(86, 50) No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/tvComment')

layout_toLeftOf 属性添加到 xml 后出现此错误。

Error:(86, 50) No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/tvComment').

应用Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '25.0.0'

    defaultConfig {
        applicationId "xx.xx.xx"
        minSdkVersion 15
        targetSdkVersion 24
        versionCode 15
        versionName '1.4.1'
        manifestPlaceholders = [onesignal_app_id: "xx-xx-xx",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "xxxxxx"]

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    aaptOptions {
        cruncherEnabled = false
    }
}

repositories {
    maven { url 'https://maven.google.com' }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.mcxiaoke.volley:library:1.0.18'
    compile 'com.github.chrisbanes.photoview:library:1.2.3'
    compile 'com.facebook.android:facebook-android-sdk:4.0.1'//4.0.1
    compile 'com.google.android.gms:play-services-ads:12.0.1'//11.8.0

    //compile 'com.google.android.gms:play-services-ads:11.2.2'

    compile 'com.pkmmte.view:circularimageview:1.1'
    compile 'com.melnykov:floatingactionbutton:1.3.0'
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    //compile 'com.android.support:appcompat-v7:26.1.0'

    compile 'com.android.support:appcompat-v7:27.1.0'
    compile 'com.android.support:cardview-v7:27.1.0'
    compile 'com.android.support:recyclerview-v7:27.1.0'
    compile 'com.android.support:design:27.1.0'
    compile 'com.balysv:material-ripple:1.0.2'
    compile 'com.google.firebase:firebase-messaging:12.0.1'
    //compile 'com.codemybrainsout.rating:ratingdialog:1.0.8'
    compile 'com.github.hotchemi:android-rate:1.0.1'
    compile 'com.onesignal:OneSignal:[3.8.3, 3.99.99]'//3.6.2
    compile 'com.google.android.gms:play-services-analytics:12.0.1'
}

apply plugin: 'com.google.gms.google-services'

项目Gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'//2.2.3

        classpath 'com.google.gms:google-services:3.2.0'//3.1.1

      //  classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()

    }
}

Xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <com.balysv.materialripple.MaterialRippleLayout
        android:id="@+id/parent"
        style="@style/MyRippleStyleLight"
        android:layout_width="match_parent"
        android:layout_height="150dp"

        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_margin="1dp"

        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            >

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/img_loading"



                />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"

                android:background="@drawable/shape_overlay"

                android:padding="10dp"
                android:layout_alignParentTop="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:orientation="horizontal"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"
                    >

                    <TextView
                        android:id="@+id/title"
                        android:layout_width="0dp"
                        android:layout_weight="1"
                        android:layout_height="wrap_content"
                        android:text="fgdhfdghdfghfdg"
                        android:maxLines="2"
                        android:ellipsize="end"
                        android:textAppearance="@style/TextAppearance.AppCompat.Title"
                        android:textColor="@android:color/white"
                        android:textStyle="normal" />
                </LinearLayout>


                <RelativeLayout
                    android:layout_width="100dp"
                    android:layout_height="30dp"
                    android:layout_alignParentRight="true"
                    >

                    <ImageView
                        android:id="@+id/im1"
                        android:src="@drawable/star"
                        android:tint="@android:color/white"
                        android:layout_width="15dp"
                        android:layout_height="13dp"
                        android:layout_centerVertical="true"
                        android:layout_toLeftOf="@id/tvComment"
                        android:layout_marginRight="2dp"

                        />

                    <TextView
                        android:id="@+id/tvComment"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                        android:text="0"
                        android:textColor="@color/white"
                        android:layout_centerVertical="true"
                        android:layout_toLeftOf="@id/im2"
                        android:layout_marginRight="5dp"/>

                    <ImageView
                        android:id="@+id/im2"
                        android:src="@drawable/comment2"
                        android:tint="@android:color/white"
                        android:layout_width="15dp"
                        android:layout_height="13dp"
                        android:layout_centerVertical="true"
                        android:layout_toLeftOf="@id/tvStar"
                        android:layout_marginRight="2dp"
                        />

                    <TextView
                        android:id="@+id/tvStar"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                        android:text="0"
                        android:textColor="@color/white"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:layout_marginRight="5dp"/>

                </RelativeLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center_vertical"
                    android:orientation="horizontal"
                    android:layout_alignParentTop="true"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true">

                    <ImageView
                        android:src="@drawable/ic_time"
                        android:tint="@android:color/white"
                        android:layout_width="20dp"
                        android:layout_height="20dp" />

                    <TextView
                        android:id="@+id/time"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="2dp"
                        android:text="Time"
                        android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                        android:textColor="@android:color/white" />
                </LinearLayout>


            </RelativeLayout>
        </RelativeLayout>
    </com.balysv.materialripple.MaterialRippleLayout>
</RelativeLayout>

昨天没有问题,我添加了layout_toleftof属性然后显示这个错误。 问题的主要原因是什么?编译Sdk版本?构建工具版本?最小SDK版本? targetSdk版本?我怎么解决这个问题?

您传递的 ID 没有 + 符号,请仔细阅读您的错误 没有资源 found that matches the given name (at 'layout_toLeftOf' with value '@id/tvComment').

这样传递您的 ID

错误在这里

 android:layout_toLeftOf="@id/tvStar"

改成这样

android:layout_toLeftOf="@+id/tvStar"

替换

android:layout_toLeftOf="@id/tvComment"

android:layout_toLeftOf="@+id/tvComment"