title: Programmatically change RelativeLayout toRightOf to toLeftOf
body: <p>i'm making chat app. I want to put timestamp besides the chat bubble. The messages will be aligned left (for received) and right (for sent). </p>
  
  <p>So, I'm looking for a way to change <code>toLeftOf</code> to <code>toRightOf</code>. For now, it looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/0AikU.png" alt="Timestamp wrongly aligned"></p>
  
  <p>Here's my XML code for each message (I have <code>ArrayAdapter</code> that handle this)</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/wrapper"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" &gt;
  
          &lt;TextView
              android:id="@+id/bubble"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textColor="#ffffff" /&gt;
  
          &lt;TextView
              android:id="@+id/timeStamp"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_centerVertical="true"
              android:layout_toRightOf="@+id/bubble" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>I googling around and found this, but doesn't work:</p>
  
  <pre><code>RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
       RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
  if(isReceivedMessage){
      params.addRule(RelativeLayout.RIGHT_OF, R.id.bubble);
  }
  else{
      params.addRule(RelativeLayout.LEFT_OF, R.id.bubble);
  }
  timeStampTextView.setLayoutParams(params);
  </code></pre>
  
  <p>Any solution? Thanks</p>