如何强制Android对话框中的文本向左对齐


var dialogView = LayoutInflater.Inflate(Resource.Layout.list_view, null);
Android.App.AlertDialog alertDialog;
listview = dialogView.FindViewById<ListView>(Resource.Id.listview);
var items = new string[] { "English", "español", "中文(s)", "中文(t)", "日本語", "हिन्दी", 
"français", "Deutsche", "русский", "عربى" };
//  var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, 
items);
var adapter = new ArrayAdapter<string>(this, Resource.Layout.list_item, items);

如果没有阿拉伯语,当列表显示时,所有项目都将向左齐平。然而,由于阿拉伯语是一种从右到左的语言,最终条目(在阿拉伯语中为阿拉伯语(显示在右侧。我想把它放在左边,这样它就能和其他的对齐。

我该怎么做?重力?

您可以android:gravity属性来定义内容的左对齐

list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#f00"
android:gravity="left"
> 
</TextView>

使用Android 4.2(sdk 17(中的LTR布局

AndroidManifest.xml中定义android:supportsRtl="true"

<application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
</application>

然后在list_item.xml:中定义android:textDirection="ltr"

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textDirection="ltr"
android:textColor="#f00"
>
</TextView>

只是忘记添加

android:gravity="left".

最新更新