-1
   <RelativeLayout
        android:id="@+id/ShortTextTip"
        android:layout_width="150dp"
        android:layout_height="200dp"
        android:background="@drawable/bg_tip_left"
        android:gravity="center"
        android:paddingBottom="7dp"
        android:paddingLeft="7dp"
        android:paddingRight="7dp"
        android:paddingTop="6dp"
        android:layout_alignParentLeft="true"
        android:visibility="visible">


    <com.me.view.text.MyTextView
           android:id="@+id/tipTitleText"
            style="@style/popupTitle"
            android:layout_width="wrap_content"
            android:layout_height="60dp"
            android:layout_alignParentTop="true"
            android:layout_gravity="left"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="38dp"
            android:layout_marginTop="10dp"
            android:gravity="left"
            android:text="Tip" />

  </RelativeLayout>

but my code doesn't change the gravity when ltrMode is on.

I want to change this programmatically.

How come?

  private void setUpforRTL(){
if (AppService.getNativeManager().getLanguageRtl()) {


    TextView addText2 = ((TextView)findViewById(R.id.tipText));
    addText2.setGravity(Gravity.RIGHT);

    TextView title = ((TextView)findViewById(R.id.tipTitleText));
    title.setGravity(Gravity.RIGHT);


}

}
joao2fast4u
  • 6,574
  • 5
  • 25
  • 41
Elad Benda
  • 30,720
  • 75
  • 234
  • 415

3 Answers3

2

You haven't specified where to put the text view, except on the relative layout. If you want, you can put it to the right as you specified by something like this:

<com.me.view.text.MyTextView
    android:id="@+id/tipText"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tipTitleLayout"
    android:layout_gravity="center"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginTop="10dp"
    android:maxLines="4"
    android:text="Navigation . everything else you need is here"
    android:textColor="#000000"
    android:layout_alignParentRight="true"
    android:textSize="16dp" />
PearsonArtPhoto
  • 35,989
  • 16
  • 107
  • 136
1

From your question, it seems that you want to do it dynamically. Try this, Try to call title.requestLayout(), when you are setting the specifications for textview.

Bette Devine
  • 1,188
  • 1
  • 8
  • 23
0

If you want to add the text view at the right side of your parent layout then try this:

<RelativeLayout
        android:id="@+id/ShortTextTip"
        android:layout_width="150dp"
        android:layout_height="200dp"
        android:background="@android:color/holo_purple"
        android:gravity="center"
        android:paddingBottom="7dp"
        android:paddingLeft="7dp"
        android:paddingRight="7dp"
        android:paddingTop="6dp"
        android:layout_alignParentLeft="true"
        android:visibility="visible">


    <TextView
        android:id="@+id/tipText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tipTitleLayout"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="10dp"
        android:maxLines="4"
        android:text="Navigation . everything else you need is here"
        android:textColor="#000000"
        android:textSize="16dp" />

  </RelativeLayout>

And if you want to right-align of the text in the textView as well then add it in your textView:

    android:gravity="right"

And if you want to do it programatically:

View aa = (View) your_textView.getParent();
aa.setGravity(Gravity.RIGHT);
Avijit
  • 3,796
  • 4
  • 31
  • 44