先上两张图吧:第一张是英语情况下,第二张是阿拉伯语下
可以看到Photos这个应用因为是英文显示的,与下面几个的显示位置都不一样。
我研究后发现,在设置显示文本所用的TextView的layout_width如果是match_parent的话就会出现如上情况,因为占满了整个空间,显示的又是英文,所以就自然的从左往右显示了,所以如果是发现TextView的layout_width为match_parent的话,一般来说将其改为wrap_content就可以了。
但是如上图示,使用的是Preference,布局是自定义的,如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" >
<ImageView
android:id="@+android:id/icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:scaleType="fitXY"
android:layout_marginEnd="16dip"
android:contentDescription="@null" />
<TextView android:id="@+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:layout_weight="1" />
</LinearLayout>
可以看出TextView的layout_width的确是wrap_content,但是也可以看到其layout_weight为1,而ImageView并没有进行相应的设置。
所以先修改LinearLayout,加上:
android:orientation="horizontal"
然后把TextView的android:layout_weight="1"去掉,这样就不会再有右显示的语言环境下英语显示方向的问题了,也会是遵从从右往左显示了。
总结,当可能出现英文时应尽量使该控件的宽度为文字宽度,这样会遵从语言显示。如果显示宽度过大,则英语会从左往右显示,导致界面的不协调。