android - 如何强制 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>
或者使用LTR
Android 4.2 (sdk 17) 的布局
android:supportsRtl="true"
在你的定义AndroidManifest.xml
<application android:allowBackup="true" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme">
</application>
然后android:textDirection="ltr"
在你的定义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:textDirection="ltr"
android:textColor="#f00"
>
</TextView>
推荐阅读
- qt - 如何在无边框窗口中保持阴影
- swift - AVAudioFile 中的 URL 为零
- .net - 是否可以使用 .NET-Core 为 Windows Mobile 6.5 制作应用程序?
- java - 几分钟后保存在 mongodb 中的记录消失了
- java - 无法解析日期时间,解析模式“ssSSS”有问题
- bitbucket - 如何为四人组免费创建 bitbucket 帐户
- java - 从 netty 服务器读取时,不同的响应消息正在合并
- python - 在没有 text.file 的程序关闭后,如何将用户数据保存在列表中?
- dialogflow-es - 格式错误的响应:由于语音响应为空,无法将 Dialogflow 响应解析为 AppResponse
- web2py - web2py的routes.py中routes_out字典的目的是什么?