当您创建一个列表并用单词填充它时,它们会自动左对齐。有没有办法进行中心对齐?
列表视图说明:
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/version"
android:layout_centerHorizontal="true"
android:id="@+id/about_list" />
用数据填充它:
listView = (ListView)findViewById(R.id.about_list);
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, R.layout.element_of_about, getResources().getStringArray(R.array.about_choose));
listView.setAdapter(adapter);
自定义标记视图 textview(element_of_about):
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Пробный текст"
style="@style/text_of_breed"
android:padding="10dp"
android:textSize="17sp"/>
使用这些设置,文本仍然位于左侧。

在标记中,
TextView更改android:layout_width="wrap_content"为android:layout_width="match_parent"