The problem can be for several reasons:
First . Add the library as a dependency in the same build.gradle
file.
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
Second . Add restrictions to your views. Example:
app:layout_constraintLeft_toLeftOf="parent"
Third . Click on any widget in your component palette (Button, EditText, TextView, etc ...) and then right click on it, in the option called Constraint Layout
, select Infer constraints
.
Fourth . Have your XML correctly to use Constraint Layout
, Example:
<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">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
If none of this works then, it will be changed to LinearLayout
or any other.