如何使ListView的文本到右的Andr​​oid? [英] How to Align ListView Text to Right in Android?

查看:169
本文介绍了如何使ListView的文本到右的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用来显示包含字符串的一个ArrayList的Andr​​oid应用程序的列表视图,我无法找到的ListView的任何属性,让我到ListView项的文本对齐的,以它的右边,而不是剩下。任何帮助将是巨大的,谢谢。

I have a list view in an Android application used to display an ArrayList containing Strings and I can't find any properties of the ListView that would allow me to align the text of the ListView Items to the right of it instead of the left. Any help would be great, thanks.

推荐答案

答案取决于你到底生成列表。如果使用标准的 ArrayAdapter ,那么你可以使用构造函数:

The answer depends on how exactly do you build the list. If you use the the standard ArrayAdapter then you could use the constructor:

ArrayAdapter<String>(Context, R.layout.aligned_right, values);

其中, R.layout.aligned_right 是这样的XML布局:

where R.layout.aligned_right is a xml layout like this:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1" 
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"                    
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:paddingLeft="6dip"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="right"/>

这篇关于如何使ListView的文本到右的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆