RTL Layout Support


Android now offers several APIs that allow you to build user interfaces that gracefully transform layout orientation to support languages that use right-to-left (RTL) UIs and reading direction, such as Arabic and Hebrew.

To begin supporting RTL layouts in your app, set the android:supportsRtl attribute to the <application> element in your manifest file and set it “true". Once you enable this, the system will enable various RTL APIs to display your app with RTL layouts. For instance, the action bar will show the icon and title on the right side and action buttons on the left, and any layouts you’ve created with the framework-provided View classes will also be reversed.

If you need to further optimize the appearance of your app when displayed with an RTL layout, there are two basic levels of optimization:

  1. Convert left- and right-oriented layout properties to start- and end-oriented layout properties.

    For example, use android:layout_marginStart in place of android:layout_marginLeft and android:layout_marginEndin place of android:layout_marginRight.

    The RelativeLayout class also provides the corresponding layout attributes to replace left/right positions, such asandroid:layout_alignParentStart to replace android:layout_alignParentLeft and android:layout_toStartOfinstead of android:layout_toLeftOf.

  2. Or to provide complete optimization for RTL layouts, you can provide entirely separate layout files using the ldrtlresource qualifier (ldrtl stands for layout-direction-right-to-left}). For example, you can save your default layout files in res/layout/ and your RTL optimized layouts in res/layout-ldrtl/.

    The ldrtl qualifier is great for drawable resources, so that you can provide graphics that are oriented in the direction corresponding to the reading direction.

Various other APIs are available across the framework to support RTL layouts, such as in the View class so that you can implement the proper behaviors for custom views and in Configuration to query the current layout direction.

Note: If you are using SQlite and have tables or column names that are “number only," be careful: usingString.format(String, Object...) can lead to errors where the numbers have been converted to their Arabic equivalents if your device has been set to the Arabic locale. You must use String.format(Locale,String,Object...) to ensure numbers are preserved as ASCII. Also use String.format("%d", int) instead of using String.valueOf(int) for formatting numbers.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值