在GitHub 的一个简单测试应用程序中,我试图显示一个用户头像,然后是两个TextView
用户名和城市(应该居中对齐),最后ListView
是ListFragment的主要内容:
在布局文件fragment_account.xml中,我尝试android:textAlignment="center"
为两个TextView
s 设置(在上面的屏幕截图中用红色箭头标记),但这没有任何效果 - 可能是因为应用程序适用于minSdkLevel=9?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/avatar"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/photo"
app:border_width="2dp"
app:border_color="#FFF"/>
<TextView <!-- how to center-align? -->
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="Username"/>
<TextView <!-- how to center-align? -->
android:id="@+id/city"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:text="City"/>
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
请告知,如果有一种很好的方法可以使这些标签居中对齐。