0

I want the image to always be on the right side of the screen without gaps no matter how long the message is (as shown in the photo). I already set android:supportsRtl="true"in the manifest.xml.

enter image description here

Here is my code

<?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"
    android:layoutDirection="rtl"
    android:layout_alignParentRight="true">

    <TextView
        android:id="@+id/message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sent_message"
        android:textSize="25sp"
        app:layout_constrainedWidth="true"
        app:layout_constraintEnd_toStartOf="@id/time"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toEndOf="@id/imageView"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/time"
        android:layout_width="100dp"
        android:layout_height="wrap_content"

        android:text="@string/time_stamp"
        android:textSize="10sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:contentDescription="@string/receiver_photo"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/send_image"
        app:layout_constrainedWidth="true"/>

</androidx.constraintlayout.widget.ConstraintLayout>
2
  • I am confused as to why not <ImageView ... app:layout_constraintRight_toRightOf=Parent .../>.? Which would directly implement "right side of the screen without gaps" Commented Mar 7, 2023 at 3:33
  • I tried app:layout_constraintRight_toRightOf=Parent, but it's still not working Commented Mar 7, 2023 at 15:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.