Constraint Layout gives error in default template in Android Studio 2.3

25,261

Solution 1

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

Solution 2

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

Look at the image example

enter image description here

Solution 3

Like that shown in picture make connection.In constraint layout we can place widgets anywhere but running on a app the widgets are not in same place where you placed during development in android studio.To fix this ,make sure a widget has both horizontal and vertical constraints by dragging from the edge connections.Widgets has round like things in each and every side, drag that to adjust to fix its position.

https://i.stack.imgur.com/r8L8O.png

Share:
25,261
Pratik Butani
Author by

Pratik Butani

Pratik Butani is Android/Flutter Lead at 7Span - Ahmedabad. He is working with Flutter Development since 2020 and Android Development since 2013. He is on the list of Top 100 User’s (85th) in India and Top 10 User’s (6th) in Gujarat as Highest Reputation Holder on StackOverflow. He was co-organizer at Google Developer Group – Rajkot in 2014-17. All-time Learner of new things, Googler and Eager to Help IT Peoples. He is also likes to share his knowledge of Android and Flutter with New Learner. SOReadyToHelp ツ Fell in Love with Android ツ I really feel proud to up-vote My Favorite #SO friend. => Android Application Developer by Passion :) => Being Helpful by Nature ;) => Now in List of Top 100 User's (85) in India and Top 10 User's (6) in Gujarat as Highest Reputation Holder on StackOverflow => Visit my blogs for learning new things : Happy to Help :) :) => My Apps on Playstore: AndroidButs & PratikButani => My Articles on Medium => Join Me on LinkedIn => Tweet Me on Twitter => Follow Me on Quora - Top Writer on Quora in 2017 => Hangout with Me on [email protected] => Social Networking Facebook => Get Users list whose bio's contains given keywords More about me :) -> Pratik Butani

Updated on July 09, 2022

Comments

  • Pratik Butani
    Pratik Butani almost 2 years

    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?