Android Java文本未居中
我试着让文本都居中,但没有成功。这是我的xml代码Android Java文本未居中,java,android,Java,Android,我试着让文本都居中,但没有成功。这是我的xml代码 <TextView android:id="@+id/creditText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20dp" android:textColor="#ffffff" android:layout_marginLeft="0dp" android:layout_marginTop=
<TextView
android:id="@+id/creditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#ffffff"
android:layout_marginLeft="0dp"
android:layout_marginTop="350dp"
android:gravity="center"
android:maxLines="6"
android:text="
Dalton Metlzer: Lead Programer/Designer
Cole Selensky: Lead Designer/Programer
Carson Rego: Lead Artist
Carly R: Logo Artist
Evan Swonke: Music Composer/Performer
Blake Jackson: Narator"
/>
相反,它只是变得一团糟
这就是它的样子
这些名称之间有空格。我假设你想要一个垂直的名字列表,在页面中居中。在本例中,不是空格,而是在每个名称的末尾,按enter键,以获得换行符。然后,您可以得到一个居中的垂直名称列表。这些名称之间有空格。我假设你想要一个垂直的名字列表,在页面中居中。在本例中,不是空格,而是在每个名称的末尾,按enter键,以获得换行符。然后你可以得到一个居中的名字列表。试试这个:
<TextView
android:id="@+id/creditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:gravity="center"
android:maxLines="6"
android:text="
Dalton Metlzer: Lead Programer/Designer
Cole Selensky: Lead Designer/Programer
Carson Rego: Lead Artist
Carly R: Logo Artist
Evan Swonke: Music Composer/Performer
Blake Jackson: Narator"
android:textColor="#ffffff"
android:textSize="20dp" />
试试这个:
<TextView
android:id="@+id/creditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:gravity="center"
android:maxLines="6"
android:text="
Dalton Metlzer: Lead Programer/Designer
Cole Selensky: Lead Designer/Programer
Carson Rego: Lead Artist
Carly R: Logo Artist
Evan Swonke: Music Composer/Performer
Blake Jackson: Narator"
android:textColor="#ffffff"
android:textSize="20dp" />
此代码可能有用
<TextView
android:id="@+id/creditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0dp"
android:layout_marginTop="350dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="20dp"
android:maxLines="6"
android:text="Dalton
Metlzer: Lead Programer/Designer\n
Cole Selensky: Lead Designer/Programer\n
Carson Rego: Lead Artist\n
Carly R: Logo Artist\n
Evan Swonke: Music Composer/Performer\n
Blake Jackson: Narator"
/>
此代码可能有用
<TextView
android:id="@+id/creditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="0dp"
android:layout_marginTop="350dp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="20dp"
android:maxLines="6"
android:text="Dalton
Metlzer: Lead Programer/Designer\n
Cole Selensky: Lead Designer/Programer\n
Carson Rego: Lead Artist\n
Carly R: Logo Artist\n
Evan Swonke: Music Composer/Performer\n
Blake Jackson: Narator"
/>
首先,您需要使用新行和all设置文本格式 而不是XML文件中的一些更改,如删除 android:layout_marginTop=“350dp” 像这样的新xml代码
<TextView
android:id="@+id/creditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="20dp"
android:textColor="#000000"
android:layout_marginLeft="0dp"
android:gravity="center"
android:maxLines="6"
android:text="
Dalton Metlzer: Lead Programer/Designer
Cole Selensky: Lead Designer/Programer
Carson Rego: Lead Artist
Carly R: Logo Artist
Evan Swonke: Music Composer/Performer
Blake Jackson: Narator"
/>
这里我不格式化文本
根据您的要求设置文本格式。首先,您需要使用新行和all设置文本格式 而不是XML文件中的一些更改,如删除 android:layout_marginTop=“350dp” 像这样的新xml代码
<TextView
android:id="@+id/creditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="20dp"
android:textColor="#000000"
android:layout_marginLeft="0dp"
android:gravity="center"
android:maxLines="6"
android:text="
Dalton Metlzer: Lead Programer/Designer
Cole Selensky: Lead Designer/Programer
Carson Rego: Lead Artist
Carly R: Logo Artist
Evan Swonke: Music Composer/Performer
Blake Jackson: Narator"
/>
这里我不格式化文本
根据您的要求设置文本格式。尝试添加以下内容:
android:layout_gravity="center"
尝试添加以下内容:
android:layout_gravity="center"
android:gravity属性在TextView的内容中生效,但由于您也有android:layout\u width=“wrap\u content”,因此您没有可以集中的位置 要么放
android:gravity="center"
android:layout_width="match_parent"
要在内部扩展文本视图并居中,或
android:layout_gravity="center_horizontally"
android:layout_width="wrap_content"
为了保持TextView的最小宽度并将其居中于其父视图上,android:gravity属性在TextView的内容中生效,但由于您还有android:layout\u width=“wrap\u content”,因此您没有居中的位置 要么放
android:gravity="center"
android:layout_width="match_parent"
要在内部扩展文本视图并居中,或
android:layout_gravity="center_horizontally"
android:layout_width="wrap_content"
要保持文本视图的最小宽度并将其置于其父视图的中心请重新编写android:layout\u marginTop=“0dp”我刚刚复制了您的代码,它正在中心查看只需执行一件事ctrl+A>>ctrl+shift+F并删除顶部边缘即可重新编写android:layout\u marginTop=“0dp”我刚刚复制了你的代码&它正在中心查看只需做一件事ctrl+A>>ctrl+shift+F&删除上边距我正在让文本从屏幕底部向上滚动,这就是为什么我在350Ok的原因。我明白,你应该在代码中添加该行,并根据你的要求格式化文本,这也很好我让文本从屏幕底部向上滚动,这就是为什么我让它在350Ok我理解,你应该在代码中添加这一行,并根据你的要求格式化文本,这也很好。