根据语言选择对齐文本视图(左-右)

2024-01-10

我有一个线性布局,其中包含水平排列的文本视图和编辑文本。我有一个选项可以在先前的活动中选择语言(英语和阿拉伯语)。当我选择英语时,当前对齐方式很好,但是当我选择阿拉伯语时,它应该从右到左显示,这意味着 textView 位置应该向右(在布局中,它将从左开始),然后是 editText。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/darkblue_bg"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<EditText
android:id="@+id/editusername"
android:layout_width="196dp"
android:layout_height="wrap_content"
android:background="@drawable/textfield_default"
android:ems="10" >

</EditText>

<TextView
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

/>

</LinearLayout>

</LinearLayout>

有人请给我解决方案...


您可以通过将布局放置在适当的布局文件夹中来指定特定于某种语言的布局。我不知道阿拉伯语的代码是什么,但应该是这样的/layout-aa/

然而,今天更好的是使用相对布局,您可以使用android:gravity="start"或类似的,根据语言方向而不是严格的左/右对齐。 API 版本 14 及更高版本提供此功能。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

根据语言选择对齐文本视图(左-右) 的相关文章

随机推荐