2014-02-06 44 views
20

首先抱歉我的英語語言弱!如何設計從右到左的線性佈局

我設計了一個佈局。這是佈局的一部分:

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

首選語言的方向是從右到左。紅色是主題,藍色是從數據庫中讀取的文本。

問題是,文本中有很多字符,並且在此佈局中顯示時,由於我的佈局是「從左到右」並且文本會填充所有佈局,因此該主題將消失。

我搜索了很多,但我找不到任何方法來改變佈局「從右到左」。

回答

12

試着這樣做:

  1. 你的LinearLayout更改爲RelativeLayout的
  2. 對齊話題​​父權
  3. 將主題文本到左的話題

這裏是一個例子:

<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> 
+0

沒關係!非常感謝你 – Sadegh

+1

android:layoutDirection =「rtl」這是一個更好的解決方案,如下所示:https://developer.android.com/reference/android/view/View.html#attr_android:layoutDirection – coder

2

將以下行添加到佈局中:

android:layoutDirection="rtl" 
android:layout_alignParentRight="true" 
相關問題