I am trying to use ConstraintLayout but every views just get stacked in the top left corner. No matter what i try i can’t get the image view to be on the right even though the constraint is there it stays on the right and at the top.
I did find this question that is similar although for him the preview seem to work, he gets trouble once he execute the app. In any case there is no answers there that helps.
Here is my layout:
<?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:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/crime_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crime Title"
app:layout_constraintBottom_toTopOf="@+id/crime_date"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/crime_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crime Date"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/crime_title" />
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_solved"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Here is a screenshot:
screenshot
2
Answers
First of all what is the android studio version that you are using.Also try it using a different layout life Relative layout or Linear layout it might work as well.
I tried using your code on to my editor of android studio and this seems to be doing what it supposed to do. Please refer to the screenshot. https://phpout.com/wp-content/uploads/2023/11/GgGY7.png
Check if your android studio and constraint layout version is set to the latest version. If this does not work then try to create a new project and then check again.