I am programmatically change the Gravity and background of TextView in ConstrainLayout the background color change correctly but the gravity don't change how to solve this problem please
 if(currentUserId.equals(model.getUserId())){
                    holder.message.setBackgroundResource(R.drawable.message_sender_bubbles);
                    holder.message.setGravity(Gravity.LEFT);
                }else
                {
                    holder.message.setBackgroundResource(R.drawable.message_resiver_bubbles);
                    holder.message.setGravity(Gravity.RIGHT);
                }
the xml is
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="8dp">
    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/image_message_profile"
        android:layout_width="32dp"
        android:layout_height="32dp"
        android:src="@drawable/profile_image"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginLeft="8dp"
        app:layout_constraintLeft_toLeftOf="parent" />
    <TextView
        android:id="@+id/text_message_name"
        android:text="user_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="12sp"
        app:layout_constraintLeft_toRightOf="@+id/image_message_profile"
        android:layout_marginLeft="8dp"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="4dp" />
 
    