Android Studio ConstraintLayout 不工作

AndroidStudio ConstrainLayout not working

我是 android studio 的新手,如果有人能帮助我,我对此感到头疼,我是否遗漏了什么?....我在约束布局方面遇到问题,问题是我放置了一些元素(ImageView , Button it does not mater) in layout and constraint it to parent 但是当我在模拟器中 运行 它只是没有显示。它也没有向我显示元素下的那些按钮连接 BaseLine 并删除该元素的约束。

"screenShot":

<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="343dp"
        android:layout_height="118dp"
        android:layout_marginTop="10dp"
        android:scaleType="centerCrop"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_c`enter code here`onstraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:srcCompat="@tools:sample/backgrounds/scenic[7]" />

</android.support.constraint.ConstraintLayout>

when i run it in emulator it just is not showing

问题在这里:

tools:srcCompat="@tools:sample/backgrounds/scenic[7]"

你需要了解什么是tools,所以我建议你稍微阅读一下文档。

记下来 :

It's a namespace that enable design-time features (such as which layout to show in a fragment) or compile-time behaviors (such as which shrinking mode to apply to your XML resources). When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.

相反,您必须使用才能在模拟器上显示它。

app:srcCompat="@drawable/your_drawable"

注意:记得加上:xmlns:app="http://schemas.android.com/apk/res-auto"

我在新的 Android Studio 3.4 中发现了 solution.it 的不同之处,您必须右键单击元素,现在可以选择显示基线。