簡體   English   中英

在包中找不到屬性“layout_constraintLeft_toLeftOf”的資源標識符

[英]No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package

我正在使用 Android SDK 2.2.3。 我正在關注一本關於 Android 編程的書。

代碼是:

<android.support.constraint.ConstraintLayout
    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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="eu.a123sandberg.webview.MainActivity"
    tools:layout_editor_absoluteX="0dp"
    tools:layout_editor_absoluteY="81dp">

    <WebView
        android:layout_width="384dp"
        android:layout_height="511dp"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp"
        app:layout_constraintLeft_toLeftOf="@+id/activity_main"
        tools:layout_constraintLeft_creator="0"
        app:layout_constraintTop_toTopOf="@+id/activity_main"
        tools:layout_constraintTop_creator="0"
        app:layout_constraintRight_toRightOf="@+id/activity_main"
        tools:layout_constraintRight_creator="0"
        app:layout_constraintBottom_toBottomOf="@+id/activity_main"
        tools:layout_constraintBottom_creator="0"
        />

</android.support.constraint.ConstraintLayout>

我用 android.support.constraint.ConstraintLayout 嘗試了三個不同的例子,在所有情況下我都得到相同的錯誤消息:

Error:(13) No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'eu.a123sandberg.webview'

build.gradle 文件包含:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "eu.a123sandberg.webview"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
                                                                                  testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-                   android.txt'), 'proguard-rules.pro'
        }
     }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-            core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    testCompile 'junit:junit:4.12'
}

我該怎么做才能解決錯誤?

我用谷歌搜索了錯誤,但無法找到解決錯誤的建議。

請幫忙。

ConstraintLayout不是 AppCompat 的一部分。 它是一個獨立的庫。

build.gradle文件中添加依賴build.gradle

implementation 'com.android.support.constraint:constraint-layout:1.1.3' 

並點擊立即Sync now

我遇到了同樣的問題,將此行添加到build.gradle(module app)解決了它。

compile 'com.android.support.constraint:constraint-layout:1.1.0-beta3'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM