记录解决英文和阿拉伯文混合的字符串,在阿拉伯环境下靠左显示,但需要从右开始显示
USBتم توصيل总是靠左显示,经过一番排查发现是因为textView只是设置 android:gravity =“start”是不好用的。还有就是拼接字符串不用用普通的s = s1+s2;
解决方案
首先要宽度要match_parent,这里用了fill_parent,因为之前的代码高度用的这个我就直接复制了,但是我觉得还是match_parent好,反正这两都一样,然后就是android:textDirection="locale"这个很重要,在纯是阿拉伯语言的时候有没有它都行,但是在混合的情况下他很重要
在就是混合字符串要用StringBuilder进行拼接,因为这样他才能将你要两个拼接的字符串识别成一个同一组字符,如果想还是靠左显示就用普通的字符串拼接,他就按照首个字符应该属于的环境显示了(也就是如果是中文英文就是从左往右)
感谢该作者带来的灵感:
原文链接:https://blog.csdn.net/m0_50930469/article/details/123188791
这里是我写的是镜像的布局:
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"
android:layout_marginLeft="@dimen/margin_size"
android:layout_marginRight="@dimen/margin_size"
android:textDirection="locale"
android:gravity="start|center_vertical"
android:textColor="#ffffffff"
android:textSize="@dimen/text_size1"
android:visibility="gone" />
还有在全局加
android:supportsRtl="true"
差点以为白改了!!!