在包中找不到属性"layout_constraintLeft_toLeftOf"的资源标识符

Jor*_*erg 36 android android-layout android-studio android-constraintlayout

我使用的是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>
Run Code Online (Sandbox Code Playgroud)

我用android.support.constraint.ConstraintLayout尝试了三个不同的例子,在所有情况下我都会收到相同的错误消息:

Error:(13) No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'eu.a123sandberg.webview'
Run Code Online (Sandbox Code Playgroud)

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'
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能解决错误?

我用Google搜索了错误,但未能找到解决错误的建议.

请帮忙.

Aka*_*tel 73

ConstraintLayout不属于AppCompat.这是一个独立的库.

build.gradle文件中添加依赖项

implementation 'com.android.support.constraint:constraint-layout:1.1.3' 
Run Code Online (Sandbox Code Playgroud)

并单击Sync now.

  • 配置“编译”已过时,已被“实现”和“ api”替换。因此使用实现'com.android.support.constraint:constraint-layout:1.1.3' (2认同)