Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android Studio中将文本居中?_Android_Xml_Android Studio_Android Layout_Android Xml - Fatal编程技术网

如何在Android Studio中将文本居中?

如何在Android Studio中将文本居中?,android,xml,android-studio,android-layout,android-xml,Android,Xml,Android Studio,Android Layout,Android Xml,我正在制作我的应用程序,我想在Android Studio中集中一段文字 这是我目前正在使用的代码 <activity android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:label="Login t

我正在制作我的应用程序,我想在Android Studio中集中一段文字

这是我目前正在使用的代码

<activity
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:label="Login to Notely"
        android:name=".ActivityLogin"/>

我想做的就是将“登录到Notely”文本放在应用程序顶部的中心


有人能帮我吗?提前感谢。

活动
应用程序
的子元素,表示必须在
AndroidManifest中定义的
活动
。xml
文件。它有许多属性,如标签、名称、主题、启动模式等。
android:label
表示一个标签,即显示在屏幕上。 它还执行一些其他任务:

  • 它负责通过提供权限来保护
    应用程序
    以访问任何受保护的部分
  • 它还声明了应用程序将要使用的android
    API
  • 它列出了插装类。插装类提供分析和其他信息。这些信息在应用程序发布前被删除
有一点很清楚,
与组织文本无关

现在,要使
活动
文本居中,必须首先在
XML
文件中定义一个
视图组
(线性布局、相对布局、约束布局等)。在本例中,我使用的是
RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context=".MainActivity">

   <TextView
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
      android:text="Hello World"
      />

</RelativeLayout>


使用
你的答案很有帮助,但我应该把这些代码放在哪里?还有一件事。可以放置图像而不是文本吗?这将对我非常有帮助。要放置您必须替换的图像,有关更多详细信息,请访问。第二,如果答案有帮助,请注明接受。