如何设置在中心的ListView android应用的文本? [英] How to set the text at center in ListView android application?
问题描述
我在我的应用程序上实现ListView控件的应用程序,我已经使用getListView()method.I写了code如下:
I have implemented an application on ListView in my application i have used getListView() method.I have written code as follows:
String[] conversionsadd = getResources().getStringArray(R.array.conversions);
setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,conversionsadd));
getListView().setTextFilterEnabled(true);
getListView().setBackgroundResource(R.drawable.listback2);
在我写上面的code在onCreate方法,我可以能够显示列表中的一些文本。 从上面的codeI想显示在中间的文字在列表中,并显示在彩色文本。
when i write the above code at onCreate method i can able to show the list with some texts. from the above code i would like to display the text in center in the list and also display the text in a color.
推荐答案
您使用的是内置的布局是
you are using built-in layout which is
android.R.layout.simple_list_item_1
这个布局不能更改。然而,你可以提供自己的行布局。
this layout cannot be changed. However you can provide your own row layout.
您行应该是这样的:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_height="?android:attr/listPreferredItemHeight"
android:layout_width="fill_parent"
android:textSize="20sp"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:gravity="center" />
记住,ID应该是唯一的机器人:ID =@机器人:ID / text1中的
,现在你可以把这个给你ArrayAdapter的构造函数:
and now you can give this to your ArrayAdapter's constructor:
ArrayAdapter<String>(this,R.layout.my_custom_layout,conversionsadd);
这篇关于如何设置在中心的ListView android应用的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!