androidの设计的布局在阿拉伯语下界面错乱的解决方法 总汇

来源:互联网 发布:java流行开源框架 编辑:程序博客网 时间:2024/05/16 06:27

一: androidの设计的布局在阿拉伯语下界面错乱的解决方法 



左边是有问题图片,,,右边是正确的图片
(1)在AndroidManifest.xml声明文件的<application>元素中,添加” android:supportsRtl=true”
(2)修改应用程序中layout的“left/right”布局属性,改为对应的”start/end”布局
 paddingStart paddingEnd layout_marginStart layout_marginEnd layout_alignParentStart layout_alignParentEnd
 替换
 paddingLeft paddingRight layout_marginLeft layout_marginRight layout_alignParentLeft layout_alignParentRight
(3)混合字符或者纯英文下,TextView没有居右。比如列表中部分纯英文字串靠左显示,翻译过的靠右显示
找到其定义的layout文件
用 match_parent替换wrap_content,如果替换后还是没有效果新增
android:textDirection="locale”这个属性。
代码控制
String language = Locale.getDefault().getLanguage();
if(language.equals("ar")||language.equals("fa")){
TextView textview =(textview )view;
textview.setGravity(Gravity.RIGHT);
(4)对于一些图片方向不对的问题
对于这些图片需要按照重新设计,然后放到drawable-ldrtl-hdpi文件夹下

二: 从右到左布局(RTL Layout)

从Android 4.2开始,Android SDK支持一种从右到左(RTL,Right-to-Left)UI布局的方式,尽管这种布局方式经常被使用在诸如阿拉伯语、希伯来语等环境中,中国用户很少使用。不过在某些特殊用途中还是很方便的。

所谓RTL,就是指按平常习惯在左的视图都会在右侧,在右侧的视图都会在左侧。例如,在线性布局中第1个子视图默认都是在左上角的,如果采用RTL布局,默认就在右上角了。

RTL布局默认是关闭的,如果想使用RTL布局,首先要在AndroidManifest.xml文件中将<application>标签的android:supportsRtl属性值设为"true",然后需要将相应视图标签的android:layoutDirection属性值设为"rtl"。

如果要使用RTL布局,还应该注意一个重要的问题。假设一个水平线性布局中有两个<TextView>标签:TextView1和TextView2。TextView1位于窗口的左上角,而TextVew2在TextView1的右侧,到TextView1的距离是100dp。实际上就是TextView2的左边缘到TextView1的右边缘的距离。如果当前是默认布局方式(LTR,从左到右,Left-to-Right),只需要将TextView2的android:layout_marginLeft属性值设为"100dp"即可。不过这在RTL布局中却恰好相反。在RTL布局中,TextView1在窗口的右上角,而TextView2却跑到了TextView1的左侧,所以TextView2到TextView1的距离实际上变成了TextView2的右边缘到TextView1的左边缘的距离。因此应该设置TextView2的android:layout_marginRight属性,这样就会造成RTL和LTR两种布局模式中UI排列的混乱。为了解决这个问题,在Android 4.2中新加了如下两个布局属性。

android:layout_marginStart:如果在LTR布局模式下,该属性等同于android:layout_marginLeft。如果在RTL布局模式下,该属性等同于android:layout_marginRight。

android:layout_marginEnd:如果在LTR布局模式下,该属性等同于android:layout_marginRight。如果在RTL布局模式下,该属性等同于android:layout_marginLeft。

首先来看下面的布局。

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  2.     android:layout_width="match_parent" 
  3.     android:layout_height="match_parent" 
  4.     android:background="#000" 
  5.     android:orientation="horizontal" > 
  6.     <TextView 
  7.         android:layout_width="wrap_content" 
  8.         android:layout_height="wrap_content" 
  9.         android:background="#F00" 
  10.         android:text="TextView1" 
  11.         android:textSize="30sp" /> 
  12.     <TextView 
  13.         android:layout_width="wrap_content" 
  14.         android:layout_height="wrap_content" 
  15.         android:layout_marginStart="100dp" 
  16.         android:background="#F00" 
  17.         android:text="TextView2" 
  18.         android:textSize="30sp" /> 
  19. </LinearLayout> 

该布局是默认的LTR布局,所以两个TextView控件都是从左到右排列的,如图8-16所示。

现在将<LinearLayout>标签的android:layoutDirection属性值设为"rtl",其他布局代码不动。再运行程序,就会看到如图8-17所示的效果。TextView1和TextView2都是从右侧开始排列的,在不改动其他代码的情况下达到这个效果,全靠TextView2使用了android:layout_marginStart属性设置了两个TextView控件的间距。

三 :android2.3.5中阿拉伯文字符显示顺序不是从右至左显示

android 2.3.5中阿拉伯语系(阿拉伯、波斯、希伯来)等在设置等界面显示还是从左至右显示,要改成从右至左显示很简单,只需改如下几个文件即可:

1.\packages\apps\Settings\res\layout\preference_icon.xml

2.\frameworks\base\core\res\res\layout\preference.xml

3.\frameworks\base\core\res\res\layout\preference_information.xml

将以上三个布局文件中TextView的属性 由android:layout_width="wrap_content"改为android:layout_widht="fill_parent"即可

阅读全文
0 0