Android 如何在XML中居中显示文本视图
如何在xml中集中文本视图 例如:Android 如何在XML中居中显示文本视图,android,xml,textview,center,Android,Xml,Textview,Center,如何在xml中集中文本视图 例如: <TextView android:id="@+id/text_3" android:text="@string/text_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:textColor="#ffffff" /> 您可
<TextView
android:id="@+id/text_3"
android:text="@string/text_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#ffffff"
/>
您可以使用
android:gravity="center"
或
设置
android:gravity=“center”
在布局和文本视图中。看这个考试
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/hello" />
</LinearLayout>
您必须将
布局添加到文本视图中
试试这个
<TextView
android:id="@+id/text_3"
android:text="@string/text_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#ffffff"
android:layout_gravity="center"
/>
您想在父布局中居中显示文本视图或在文本视图中居中显示文本的可能重复项?如果您搜索或用谷歌搜索它,您将很容易得到答案,-1感谢您的努力…它被设计成一个有助于其他人使用谷歌的索引。我回答了。这是一个问答式的问题。我知道答案,只是想帮助那些不这样做的人。在文本视图中居中显示文本。将重心设置为“居中”将使文本视图中的文本居中,而将文本视图垂直和水平居中即可。
<TextView
android:id="@+id/text_3"
android:text="@string/text_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textColor="#ffffff"
android:layout_gravity="center"
/>