安卓:围绕项目在ListView [英] Android : Centering Items in a ListVIew
问题描述
我刚开始学习Android的一个简单的项目和想法,以帮助我学习。
I have just started learning Android and thought of a simple project to help me learn.
我创建使用一个ListView上的LinearLayout一个简单的菜单。
I have created a simple menu using a ListView on a LinearLayout.
我想要做的就是中心在ListView文本,也陆续在ListView布局。
What I want to do is center the text in the ListView and also center the ListView in the layout.
我试着设置重力中心Hozitonal,但没有奏效。
I tried setting gravity to center-Hozitonal but that didn't work.
推荐答案
您可以设置重力
(而不是 layout_gravity
)属性来居中文本。请确保您还设置 layout_width
设置为FILL_PARENT
。例如,在 my_text_view.xml
:
You can set the gravity
(not layout_gravity
) attribute to center text. Make sure that you also set layout_width
is set to "fill_parent"
. For example, in my_text_view.xml
:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"/>
然后你就可以使用 R.id.my_text_view
作为资源ID。
这篇关于安卓:围绕项目在ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!