Constraint Layout gives error in default template in Android Studio 2.3

Pratik Butani picture Pratik Butani · Mar 30, 2017 · Viewed 24.6k times · Source

I've updated Android Studio 2.3, after that I am getting default ConstrainLayout as template xml.

But in that I have RelativeLayout as Child Layout and I getting following warning.

This view is not constrained, it only has designtime positions, so it will jump to (0,0) unless you add constraints.

The layout editor allows you to place widgets anywhere on the canvas, and it records the current position with design time attributes (such as layout_editor_absoluteX.) These attributes are not applied at runtime, so if you push your layout on a device, the widgets may appear in a different location than shown in the editor. To fix this, make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.

<?xml version="1.0" encoding="utf-8"?>
<layout 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.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="com.pratikbutani.demoapp.MainActivity"
        tools:showIn="@layout/activity_main">

        <RelativeLayout 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/content_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:showIn="@layout/activity_main"
            tools:layout_editor_absoluteY="8dp"
            tools:layout_editor_absoluteX="8dp">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/my_recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true" />

        </RelativeLayout>

    </android.support.constraint.ConstraintLayout>
</layout>

Getting warning on RelativeLayout, What should I do?

Answer

J. Shiv picture J. Shiv · Mar 30, 2017

Go to Design, right-click on relative layout and select Constraint layout-->Infer Constraintsenter image description here