0
我有一個擴展ViewGroup類的自定義佈局,如何以編程方式修改佈局以支持從右到左的語言,例如阿拉伯語,波斯語等。這意味着顛倒佈局項目或鏡像的順序?Android中從右到左語言的自定義佈局
我有一個擴展ViewGroup類的自定義佈局,如何以編程方式修改佈局以支持從右到左的語言,例如阿拉伯語,波斯語等。這意味着顛倒佈局項目或鏡像的順序?Android中從右到左語言的自定義佈局
沒有必要以編程方式執行此操作 從Android api 17(4.2我認爲)開始,您可以根據設備區域設置動態定義項目在屏幕上的位置。
它應該是這個樣子:
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/profile_settings_list_options"
android:drawablePadding="28dp"
android:drawableStart="@drawable/profile_settings_list_options"
android:gravity="start"
android:paddingBottom="16dp"
android:paddingLeft="28dp"
android:paddingStart="28dp"
android:paddingTop="16dp"
android:textColor="@color/gray_dark3"
android:textSize="@dimen/text_size_small2" />
欲瞭解更多,請閱讀本blogpost
有支持RTL在XML屬性。另外,嘗試在xml佈局中使用開始和結束屬性 – thepoosh
感謝您的建議,但我有一個自定義佈局,它是作爲java類文件實現的,所以我需要修改它以支持從右到左的語言。 –
然後你正在尋找'View'方向的方法,例如http://developer.android.com/reference/android/view/View.html#setLayoutDirection(int) – thepoosh