【问题标题】:Error:(86, 50) No resource found that matches the given name (at 'layout_toLeftOf' with value '@id/tvComment') [duplicate]错误:(86、50)找不到与给定名称匹配的资源(在“layout_toLeftOf”处,值为“@id/tvComment”)[重复]
【发布时间】:2018-11-23 03:57:15
【问题描述】:

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

错误:(86, 50) 找不到与给定名称匹配的资源(在 'layout_toLeftOf' 的值为 '@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版本?构建工具版本? minSdkVersion?目标SDK版本?我怎么解决这个问题?

【问题讨论】:

  • layout.xml 将与您的问题更相关。你能用它更新你的问题吗?
  • layout.xml 没有问题。没有错误,没有红色检查。这个问题是关于 gradle 文件而不是布局。我不想让问题变得更复杂。这就是我没有添加的原因。
  • 好的...我正在添加。
  • gradle 是构建工具,应该报告你的 XML 错误,所以添加 XML。

标签: java android android-studio android-gradle-plugin android-support-library


【解决方案1】:

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

错误就在这里

 android:layout_toLeftOf="@id/tvStar"

改成这样

android:layout_toLeftOf="@+id/tvStar"

【讨论】:

    【解决方案2】:

    替换

    android:layout_toLeftOf="@id/tvComment"

    android:layout_toLeftOf="@+id/tvComment"

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多