android - (Android Studio)在包(我的东西)中找不到属性“layout_constraint(全部)的资源标识符”

标签 android xml

使用 Android Studio 创建游戏,我正在尝试创建开始屏幕菜单 XML。我的意思是我们的教授给了我们一份直接复制的内容,我照做了。

但是,我收到以下错误:

Error:(11) No resource identifier found for attribute 'layout_constraintHorizontal_bias' in package 'edu.udel.myname.FlappyBird'
C:\Users\firstlast\AndroidStudioProjects\FlappyBird\app\src\main\res\layout\activity_bird.xml
Error:(11) No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'edu.udel.myname.FlappyBird'
Error:(11) No resource identifier found for attribute 'layout_constraintRight_toRightOf' in package 'edu.udel.myname.FlappyBird'
Error:(11) No resource identi`fier found for attribute 'layout_constraintTop_toTopOf' in package 'edu.udel.myname.FlappyBird'
Error:(22) No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'edu.udel.myname.FlappyBird'
Error:(22) No resource identifier found for attribute 'layout_constraintTop_toBottomOf' in package 'edu.udel.myname.FlappyBird'
C:\Users\firstlast\AndroidStudioProjects\FlappyBird\app\build\intermediates\res\merged\debug\layout\activity_bird.xml
Error:(11) No resource identifier found for attribute 'layout_constraintHorizontal_bias' in package 'edu.udel.myname.FlappyBird'
Error:(11) No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'edu.udel.myname.FlappyBird'
Error:(11) No resource identifier found for attribute 'layout_constraintRight_toRightOf' in package 'edu.udel.myname.FlappyBird'
Error:(11) No resource identifier found for attribute 'layout_constraintTop_toTopOf' in package 'edu.udel.myname.FlappyBird'
Error:(22) No resource identifier found for attribute 'layout_constraintLeft_toLeftOf' in package 'edu.udel.myname.FlappyBird'
Error:(22) No resource identifier found for attribute 'layout_constraintTop_toBottomOf' in package 'edu.udel.myname.FlappyBird'
Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt

XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:orientation="vertical"
    android:weightSum="1.0"
    tools:context="edu.udel.myname.FlappyBird.bird.FlappyBirdActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:src="@drawable/frame_1"
        android:layout_weight="0.4"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/highScores"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:text=""
        android:layout_weight="0.2"
        android:layout_gravity="center"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView"
        android:layout_marginStart="16dp" />

    <Button
        android:id="@+id/play"
        android:layout_width="wrap_content"
        android:layout_height="12dp"
        android:text="Play"
        android:layout_weight="0.1"
        android:layout_gravity="center"/>

    <Button
        android:id="@+id/demo"
        android:layout_width="wrap_content"
        android:layout_height="12dp"
        android:text="Demo"
        android:layout_weight="0.1"
        android:layout_gravity="center"/>

    <Button
        android:id="@+id/instructions"
        android:layout_width="wrap_content"
        android:layout_height="12dp"
        android:text="Instructions"
        android:layout_weight="0.1"
        android:layout_gravity="center"/>

    <Button
        android:id="@+id/quit"
        android:layout_width="wrap_content"
        android:layout_height="12dp"
        android:text="Quit"
        android:layout_weight="0.1"
        android:layout_gravity="center"/>


</LinearLayout>

最佳答案

属性“layout_constraintHorizo​​ntal_bias”适用于ConstraintLayout 。但是,在您的布局文件中,有一个 LinearLayout。

尝试用 ConstraintLayout 替换 LinearLayout。

您可能还需要添加

compile 'com.android.support.constraint:constraint-layout:1.0.2'

到此应用模块的 build.gradle 文件中的依赖项 block 。

关于android - (Android Studio)在包(我的东西)中找不到属性“layout_constraint(全部)的资源标识符”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43991347/

相关文章:

android - 如何使用其所有属性扩展小部件

java - Android Firebase - 无法从 Firebase 快照接收正确的 JSON

java - SQLiteOpenHelper 的说明

xml - 我们如何在不下载其源代码的情况下使用 EXSLT?

xml - 使用 perl 解析大型 (100 Mb) XML 文件时出现 "Out of memory"

xml - 将日期从 yyyy-mm-dd 转换为 dd/mm/yyyy 以满足 xslt 中的空日期或空日期

java - 数据库插入时出现 NullPointerException

android - 在 OpenCV Android 中访问相机帧像素

c# - 使用 XPath 通过名称属性值查找节点

c# - XML 将列表对象序列化为从 XSD 文件生成的 XmlText (XmlTextAttribute)