左右布局方案

因某些国家的阅读习惯是从右往左阅读,我们需要实现界面的左往右 右往左两种布局,有几种方式实现这种效果

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

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值