因某些国家的阅读习惯是从右往左阅读,我们需要实现界面的左往右 右往左两种布局,有几种方式实现这种效果
1.使用Android属性android:textDirection android:layoutDirection
Android Property “android:textDirection android:layoutDirection”(XML side)
Value: locale ltr rtl
Demo:sloped_secret_screen.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr"
android:orientation="vertical">
使用情景
不同区域, 界面类似.由于仅仅可以修改左右位置,受限最大
2.不同区域使用不同Dimension (XML side)
dimension in ar文件夹
36dp
824dp
38dp
84dp
dimension in other country
73.7dp
4dp
920dp
0dp
4dp
使用场景
不同区域, 界面类似.由于仅仅可以修改位置,受限较大
3.不同区域使用不同xml(XML side)
使用场景
左右布局差别很大,不是界面左右对换这么简单的情况
但是相当于维护了两套界面 维护成本上升
PS 我们可以把页面拆分,只为差异部分创建两份xml
4.系统属性(Java code side)
将区域信息在程序初始化的时候存储起来,进入界面的时候判断region 读取不同的xml或者对界面布局做调整
private void initSettingItemPageViews() {
if (SettingsHelper.isKrRegion()) {
layoutRes = new int[]{R.layout.sloped_key_address_detail, R.layout.sloped_map_preferences, R.layout.sloped_route_type,
R.layout.sloped_voice_control, R.layout.sloped_traffic_preferences, R.layout.sloped_alert_preferences,
R.layout.sloped_settings_historymanager_layout, R.layout.sloped_settings_about_layout};
} else if (MapUpdateValidHelper.isMapUpdateSubscribe()) {
layoutRes = new int[]{R.layout.sloped_key_address_detail, R.layout.sloped_map_preferences, R.layout.sloped_preferred_route,
R.layout.sloped_voice_control, R.layout.sloped_traffic_preferences, R.layout.sloped_alert_preferences, R.layout.sloped_settings_historymanager_layout,
R.layout.sloped_predictive_navigation, R.layout.sloped_settings_mapupdate_layout, R.layout.sloped_settings_about_layout};
} else {
layoutRes = new int[]{R.layout.sloped_key_address_detail, R.layout.sloped_map_preferences, R.layout.sloped_preferred_route,
R.layout.sloped_voice_control, R.layout.sloped_traffic_preferences, R.layout.sloped_alert_preferences, R.layout.sloped_settings_historymanager_layout,
R.layout.sloped_predictive_navigation, R.layout.sloped_settings_about_layout};
}
......
}
5. Summary
1.我们可以选择其中合适的一种或多种方式实现我们想要的效果
2.我们维护界面时候要考虑我们的修改是否引起其他国家界面的bug