开发者

Android : Centering Items in a ListVIew

I have just started learning Android and thought of a simple project to help me learn.

I have created a simple menu using a ListView on a LinearLayout.

What I want to do is center the text in the ListView and also center the ListV开发者_如何学Pythoniew in the layout.

I tried setting gravity to center-Hozitonal but that didn't work.


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"/>

And then you can use R.id.my_text_view as your resource id.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜