30

First sorry about my weak English language!

I designed a layout. This is part of the layout:

 <ScrollView android:id="@+id/scrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dip" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/shape_details" android:orientation="vertical" android:padding="10dip" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" > <TextView android:id="@+id/txt_details_ostan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:text="Medium Text" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#0000FF" /> <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="استان" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#AA0000" /> </LinearLayout> 

Preferred language direction is right to left. The red colors are topic, and the blue ones are text that will read from database.

The problem is that the text has many characters and when shown in this layout, the topic will be disappeared because of my layout is "left to right" and the text fill all layout.

I searched a lot but I can't find any way to change the layout "right to left".

4 Answers 4

25

Add the following line to your layout:

android:layoutDirection="rtl" android:layout_alignParentRight="true" 
Sign up to request clarification or add additional context in comments.

1 Comment

if in manifest support rtl is false then layoutDirection not working
13

Try doing this:

  1. Change your LinearLayout to a RelativeLayout
  2. Align the topic to parent right
  3. Put subject text to left of the topic

Here's an example:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="fill_parent" android:padding="5dip" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dip" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="right" > <TextView android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="استان" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#AA0000" /> <TextView android:id="@+id/txt_details_ostan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="right" android:layout_toLeftOf="@+id/textView3" android:text="This is a sample of a long message. It will not push the topic off screen." android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#0000FF" /> </RelativeLayout> </LinearLayout> </ScrollView> 

2 Comments

android:layoutDirection="rtl" this is a better solution, as shown in: developer.android.com/reference/android/view/…
کلک مرغابی زدی:) ولی راست به چپ نیست
0

if you come here, then you should not miss this magic solution called flexbox.

you can arrange items from left to right or vise versa for top to down just with changing one parameter.

example:

 <com.google.android.flexbox.FlexboxLayout android:paddingLeft="12dp" android:paddingRight="12dp" android:layout_width="match_parent" android:layout_height="match_parent" app:alignContent="flex_start" app:alignItems="flex_start" app:flexWrap="wrap"> <Item1/> <Item2/> <Item3/> <Item4/> <Item5/> </com.google.android.flexbox.FlexboxLayout> 

above five items are arranged from left to right. you just need to add one line so you can arrange it from right to left. this line is:

 app:flexDirection="row_reverse" 

it will be like this:

 <com.google.android.flexbox.FlexboxLayout android:paddingLeft="12dp" android:paddingRight="12dp" android:layout_width="match_parent" android:layout_height="match_parent" app:alignContent="flex_start" app:alignItems="flex_start" app:flexDirection="row_reverse" app:flexWrap="wrap"> 

Comments

0

One mistake I can see here if you putting left and right fixed margin. Eg - 10 and 10 from left and right, then you should set the >= from right margin. it help to get right to left content.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.