2

I am new to constrain layout and after reading documentations i know that view must have 1 horizontal and 1 vertical coordinates but whenever i drag a new view into design it move to 0,0 coordinates

View At top left

My XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">


    <ImageView
        android:id="@+id/imageView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:layout_marginTop="181dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:srcCompat="@tools:sample/avatars" />

    <ImageButton
        android:id="@+id/imageButton3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="@+id/imageView3"
        app:layout_constraintEnd_toEndOf="@+id/imageView3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ic_add_friend" />

</androidx.constraintlayout.widget.ConstraintLayout>

I already set views vertical and horizontal constrain but it still hangs at the top left also tried with vertical and horizontal bias but views sticks to top left.Please help

I also checked this and this but not working for me.

androidXP
  • 1,692
  • 3
  • 27
  • 58
  • Its a android studio layout editor specific bug. Have you tried running the app and see ? Also try selecting **File > Invalidate Caches/Restart** – Syed Ahmed Jamil Nov 27 '19 at 01:02
  • @SyedAhmedJamil are you sure it's a bug not an issue on my side? – androidXP Nov 27 '19 at 01:04
  • yes happens sometimes. Layout editor tries to show the output the you will see once you run the app but it is not 100% accurate all the time. Have you tried running the app and see where you view actually lies when app is running ? – Syed Ahmed Jamil Nov 27 '19 at 01:08
  • I know it would show at right place on app but that's what constrainlayout meant for to simplify process of designing – androidXP Nov 27 '19 at 01:10
  • that's why I said it is a bug. Either try going to **File > Invalidate Caches/Restart** or update your android studio. What version are you using ? – Syed Ahmed Jamil Nov 27 '19 at 01:13
  • Android Studio 3.5.2 – androidXP Nov 27 '19 at 01:30
  • have you tried invalidating cache and restart as well ? Does your problem still persists ? – Syed Ahmed Jamil Nov 27 '19 at 01:34
  • Yes the problem still there in my android studio not getting it work at all – androidXP Nov 27 '19 at 01:36
  • Meanwhile try completely resetting android studio by closing android studio then deleting the `.AndroidStudio3.5` folder from your USERS\\[PC NAME] and re launching it again. Hope it helps – Syed Ahmed Jamil Nov 27 '19 at 01:56
  • Also can you can share your app `build.gradle` file I want to see which version of `ConstraintLayout` and `appcompat` you are using – Syed Ahmed Jamil Nov 27 '19 at 02:03
  • @SyedAhmedJamil i am using `implementation "androidx.constraintlayout:constraintlayout:2.0.0-beta2" ` and i will try with deleting android studio files – androidXP Nov 27 '19 at 02:34
  • Sure and also try to use `'androidx.constraintlayout:constraintlayout:1.1.3'` instead. It is the latest stable version. – Syed Ahmed Jamil Nov 27 '19 at 02:38
  • `1.1.3` doesn't support motion layout which is our need – androidXP Nov 27 '19 at 02:42
  • then try an older or newer version of `2.0` from here https://mvnrepository.com/artifact/com.android.support.constraint/constraint-layout?repo=google – Syed Ahmed Jamil Nov 27 '19 at 02:51

1 Answers1

0

It happens sometimes if we move around commits. For me it's mostly build related issue. Building the project or make project would fix this issue.

Dushyant Suthar
  • 673
  • 2
  • 9
  • 27