title: How to set gravity in a linearlayout in recyclerview?
body: <p><a href="https://i.stack.imgur.com/keVC1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/keVC1.png" alt="enter image description here"></a>i  am working with recyclerview and i want to set gravity of a Linearlayout left or right in recyclerview .but my Linearlayout alwayas set in left my code is shown below.</p>
  
  <pre><code> @Override
      public void onBindViewHolder(MessageWindowHolder holder, int position) {
          if(notificationDescriptions.get(position).getIsRecieve())
          {
              holder.linearLayout.setGravity(Gravity.LEFT);
              holder.messageTextview.setText(notificationDescriptions.get(position).getMessage());
              holder.messageTextview.setBackground(notificationDescriptionActivity.getResources().getDrawable((R.drawable.bubble_a)));
          }
          else {
              holder.linearLayout.setGravity(Gravity.RIGHT);
              holder.messageTextview.setText(notificationDescriptions.get(position).getMessage());
              holder.messageTextview.setBackground(notificationDescriptionActivity.getResources().getDrawable(R.drawable.bubble_b));
          }
  
      }
  </code></pre>
  
  <p>notification_message.xml</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" &gt;
  
      &lt;LinearLayout
          android:id="@+id/singleMessageContainer"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;TextView
              android:id="@+id/singleMessage"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:layout_margin="5dip"
              android:background="@drawable/bubble_a"
              android:paddingLeft="10dip"
              android:text="Hello bubbles!"
              android:textColor="@android:color/primary_text_light" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>viewholder.java</p>
  
  <pre><code>public class MessageWindowHolder extends RecyclerView.ViewHolder {
      protected LinearLayout linearLayout;
      protected TextView messageTextview;
  
  
      public MessageWindowHolder(View view, List&lt;NotificationDescription&gt; notificationDescriptions) {
          super(view);
          this.linearLayout = (LinearLayout)view.findViewById(R.id.singleMessageContainer);
          this.messageTextview = (TextView)view.findViewById(R.id.singleMessage);
      }
  }
  </code></pre>
  
  <p>Main layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context="com.mindefy.kidster.activity.NotificationDescriptionActivity"
      tools:showIn="@layout/activity_notification_description"&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:id="@+id/notificationRecyclerViewParent"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="80dp" /&gt;
      &lt;EditText
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:fontFamily="serif"
          android:id="@+id/sendMessageEdittext"
          android:layout_centerHorizontal="true"
          android:layout_alignParentBottom="true"
          android:layout_marginBottom="20dp"
     /&gt;
      &lt;Button
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:layout_alignTop="@+id/sendMessageEdittext"
          android:layout_alignParentRight="true"
          android:id="@+id/sendMessageReplyButton"
          android:layout_alignParentEnd="true"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>