0
<LinearLayout
        android:id="@+id/tipTitleLayout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="2dp"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <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" />

    </LinearLayout>

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);

        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams)title.getLayoutParams();
        params.gravity = Gravity.RIGHT;

        title.setLayoutParams(params); //causes layout update

    }

}
Elad Benda
  • 30,720
  • 75
  • 234
  • 415

3 Answers3

0

You should call requestLayout on the surrounding view after updating the layout parameters.

Jonas Winkler
  • 378
  • 1
  • 8
0

Try this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tipTitleLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="right|center_vertical"
    android:padding="10dp"
    android:orientation="horizontal" >

    <com.me.view.text.MyTextView
        android:id="@+id/tipTitleText"
        style="@style/popupTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Tip" />

</LinearLayout>
Biraj Zalavadia
  • 27,124
  • 9
  • 56
  • 73
-1

Change declaration of title to LinearLayout since you defined it as LL in xml.

ornay odder
  • 135
  • 5