1

How do I move this chat layout(black one) to right side with the help of java code?

I'm making a chat app and i want the message sent by me in the right side and msg sent by another person in the left side(as shown in the screenshot)

enter image description here

the code of my chat layout is:

`<?xml version="1.0" encoding="utf-8"?>
    <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/message_single_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="5dp">

        <de.hdodenhof.circleimageview.CircleImageView
            android:id="@+id/message_profile_layout"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginTop="4dp"
            android:src="@drawable/default_profile" />

        <com.daasuu.bl.BubbleLayout
            android:id="@+id/message_bubble_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginStart="3dp"
            android:layout_toEndOf="@+id/message_profile_layout"
            android:padding="8dp"
            app:bl_arrowDirection="left"
            app:bl_arrowHeight="8dp"
            app:bl_arrowPosition="12dp"
            app:bl_arrowWidth="8dp"
            app:bl_bubbleColor="@color/black"
            app:bl_cornersRadius="10dp">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:orientation="horizontal"
                android:padding="2dp">

                <TextView
                    android:id="@+id/message_text_layout"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginStart="4dp"
                    android:text="Message Here"
                    android:textColor="@color/white"
                    android:textSize="16sp" />

                <TextView
                    android:id="@+id/time_view_layout"
                    android:layout_width="32dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="10dp"
                    android:layout_weight="1"
                    android:text="00:00"
                    android:textColor="@color/white"
                    android:textSize="12sp" />

            </LinearLayout>

        </com.daasuu.bl.BubbleLayout>

    </RelativeLayout>'
Munir
  • 2,548
  • 1
  • 11
  • 20
Ketan Choyal
  • 93
  • 2
  • 7

1 Answers1

0

You will need to create two viewholders for this, which will have different layouts according to the user type. Look at this answer on how to do that You will basically select the viewType on the basis of message, whether the user is self or other, and accordingly show the appropriate view.

karandeep singh
  • 2,294
  • 1
  • 15
  • 22