无法使用约束布局

时间:2018-10-08 14:07:11

标签: android

C:\Users\Juan\AndroidStudioProjects\Sinergi\app\src\main\res\layout\activity_feed.xml:90: error: attribute layout_constraintStart_toStartOf (aka com.living_algorithm.sinergi:layout_constraintStart_toStartOf) not found.
C:\Users\Juan\AndroidStudioProjects\Sinergi\app\src\main\res\layout\activity_feed.xml:90: error: attribute layout_constraintTop_toBottomOf (aka com.living_algorithm.sinergi:layout_constraintTop_toBottomOf) not found.

我的错误

Command: C:\Users\Juan\.gradle\caches\transforms-1\files-1.1\aapt2-3.2.0-4818971-windows.jar\54a0692c01a8c149cd9024715c187bd5\aapt2-3.2.0-4818971-windows\aapt2.exe link -I\
        C:\Users\Juan\AppData\Local\Android\Sdk\platforms\android-28\android.jar\
        --manifest\
        C:\Users\Juan\AndroidStudioProjects\Sinergi\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml\
        -o\
        C:\Users\Juan\AndroidStudioProjects\Sinergi\app\build\intermediates\processed_res\debug\processDebugResources\out\resources-debug.ap_\
        -R\
        @C:\Users\Juan\AndroidStudioProjects\Sinergi\app\build\intermediates\incremental\processDebugResources\resources-list-for-resources-debug.ap_.txt\
        --auto-add-overlay\
        --java\
        C:\Users\Juan\AndroidStudioProjects\Sinergi\app\build\generated\not_namespaced_r_class_sources\debug\processDebugResources\r\
        --custom-package\
        com.living_algorithm.sinergi\
        -0\
        apk\
        --output-text-symbols\
        C:\Users\Juan\AndroidStudioProjects\Sinergi\app\build\intermediates\symbols\debug\R.txt\
        --no-version-vectors
Daemon:  AAPT2 aapt2-3.2.0-4818971-windows Daemon #0

在拖动某些图像和文本时,我自动收到此错误。谁能帮我吗?

这是我的代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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"
    tools:context=".feed"
    android:id="@+id/drawerLayout">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.constraint.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

我的图片视图

<ImageView
                android:id="@+id/imageView5"
                android:layout_width="329dp"
                android:layout_height="188dp"
                android:layout_marginStart="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="12dp"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.205"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/imageView6"
                app:srcCompat="@drawable/photo1" />

            <ImageView
                android:id="@+id/imageView6"
                android:layout_width="51dp"
                android:layout_height="73dp"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/face" />

我的文字视图

  <TextView
                android:id="@+id/textView8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                android:text="John Wick"
                android:textColor="@android:color/holo_blue_dark"
                android:textStyle="bold"
                app:layout_constraintBottom_toTopOf="@+id/textView11"
                app:layout_constraintStart_toEndOf="@+id/imageView6"
                app:layout_constraintTop_toTopOf="parent" />

my Text View


 <TextView
                android:id="@+id/textView10"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:text="German far-right mobilized by 'fake news' after stabbing: officials"
                android:textColor="@android:color/background_dark"
                android:textSize="24sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/imageView5" />

            <TextView
                android:id="@+id/textView11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginBottom="16dp"
                android:text="Reporter"
                android:textColor="@android:color/darker_gray"
                app:layout_constraintBottom_toTopOf="@+id/imageView5"
                app:layout_constraintStart_toEndOf="@+id/imageView6"
                app:layout_constraintTop_toBottomOf="@+id/textView8" />

下一行

<TextView
                android:id="@+id/textView12"
                android:layout_width="0dp"
                android:layout_height="90dp"
                android:layout_marginStart="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:text="DRESDEN/BERLIN (Reuters) - Far-right groups spread “fake news” on social media to mobilize their supporters for violent protests targeting migrants after the fatal stabbing of a German man, said officials in the eastern German state of Saxony where they took place."
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="1.0"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView10" />
        </android.support.constraint.ConstraintLayout>
    </LinearLayout>
    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:menu="@menu/menu"
        android:layout_gravity="start">

    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>

有人可以帮助我吗?我不知道为什么在移动图像后会发生这种情况,还是应该将gradle插件从3.2.0降级到3.1.4,因为我听说它总是在gradle插件版本3.2.0中发生

2 个答案:

答案 0 :(得分:0)

您需要将强制性属性app:layout_constraintStart_toStartOfapp:layout_constraintTop_toBottomOf添加到XML中,以定义Constraintlayout

答案 1 :(得分:0)

可能您没有正确使用app名称空间。我猜您正在像下面这样引用layout_constraintStart_toStartOf

<SomeView app:layout_constraintStart_toStartOf="..." />

并且在xml文件中没有正确引用应用程序名称空间。

如果ConstraintLayout是您的根视图,则它必须类似于以下内容

<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" />

注意xmlns:app的值。

如果您需要在应用包中引用自定义视图的自定义属性,则必须在根视图中定义其他名称空间

xmlns:custom="http://schemas.android.com/apk/res/com.example.customviews"