简体   繁体   English

如何居中文本

[英]How to center text

So I am writing a program which includes a main menu, and for the main menu I use the following code snip, My question is how can I get the items that it makes appear to be centered rather than left align. 所以我正在编写一个包含主菜单的程序,而对于主菜单,我使用下面的代码片段,我的问题是如何才能使它所显示的项目看起来居中而不是左对齐。

setListAdapter(new ArrayAdapter<String>(MainMenu.this, android.R.layout.simple_list_item_1, Actions));

thanks for any help 谢谢你的帮助

Create a custom TextView and use that instead of android.R.layout.simple_list_item . 创建一个自定义TextView并使用它而不是android.R.layout.simple_list_item

For example, create a layout called "textview.xml" and use something like this: 例如,创建一个名为“textview.xml”的布局并使用以下内容:

<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/arrayTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"/>

Then just use R.layout.textview to reference it in your ArrayAdapter . 然后使用R.layout.textviewArrayAdapter引用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM