title: How to set gravity of textview programatically with RelativeLayout?
body: <p>I am developing an android app. I am populating ListView by inflating rows as follows:</p>
  
  <pre><code>public class MyListAdapter extends BaseAdapter {
      Context con;
      private LayoutInflater layoutinf;
      ArrayList&lt;Boolean&gt; itemChecked = new ArrayList&lt;Boolean&gt;();
      ArrayList&lt;String&gt; items_ = new ArrayList&lt;String&gt;();
  
      public MyListAdapter(ChatActivity context) {
          con = context;
      }
  
      public int getCount() {
          return item_id.size();
      }
  
      public Object getItem(int position) {
          return item_id.size();
      }
  
      public long getItemId(int position) {
          return item_id.get(position).hashCode();
      }
  
      public View getView(final int position, View arg1, ViewGroup arg2) {
  
          View v = arg1;
          ViewHolder holder = null;
          if (v == null) {
              layoutinf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              v = layoutinf.inflate(R.layout.row_chat, null);
              holder = new ViewHolder();
  
          //  holder.tv_contact = (TextView) v.findViewById(R.id.phone_num);
              holder.tv_sms_body = (TextView) v.findViewById(R.id.msg_body);
              holder.tv_time = (TextView) v.findViewById(R.id.time);
  
              v.setTag(holder);
          } else {
              holder = (ViewHolder) v.getTag();
          }
  
          if(item_flag.get(position).equals("1"))
          {
              holder.tv_sms_body.setBackgroundResource(R.drawable.bubble_green);
  
          }
                      else if(item_flag.get(position).equals("0"))
                      {
                          holder.tv_sms_body.setBackgroundResource(R.drawable.bubble_yellow);
  
                      }
  
  
          //holder.tv_contact.setText("" + item_phone_num.get(position));
          holder.tv_sms_body.setText(item_msg_body.get(position));
          holder.tv_time.setText(item_time.get(position));
  
          return v;
      }
  }
  </code></pre>
  
  <p>Layout file is as follows:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  
  
  &lt;TextView
      android:id="@+id/msg_body"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignRight="@id/phone_num"
      android:layout_below="@id/phone_num"
      android:text="SMS"
      android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
  &lt;TextView
      android:id="@+id/time"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentRight="true"
      android:layout_below="@id/msg_body"
      android:text="time"
      android:textSize="12dp"
      android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>How can i set TextView gravity right programatically using RelativeLayout in above Code???</p>