Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constraint Layout gives error in default template in Android Studio 2.3

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?

like image 253
Pratik Butani Avatar asked Mar 30 '17 12:03

Pratik Butani


2 Answers

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

like image 64
J. Shiv Avatar answered Sep 18 '22 11:09

J. Shiv


Drag the object to connect to the walls...Create connections between walls and object

Look at the image example

enter image description here

like image 30
N Droidev Avatar answered Sep 19 '22 11:09

N Droidev