Android 要从屏幕中央开始,垂直显示两个按钮,每个按钮上下重叠-仅显示一个按钮

Android 要从屏幕中央开始,垂直显示两个按钮,每个按钮上下重叠-仅显示一个按钮,android,xml,user-interface,Android,Xml,User Interface,这是我第一次使用XML和Android,所以我是一个真正的noob。我想要两个按钮登录和创建帐户,其中登录位于屏幕中央,创建帐户位于屏幕正下方 我现在只有创建帐户按钮,它位于屏幕的顶部,而不是中央。由于某些原因,登录在任何地方都不会出现。有人能看一下我的XML文档,看看他们是否能发现发生这种情况的原因吗 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http:/

这是我第一次使用XML和Android,所以我是一个真正的noob。我想要两个按钮<代码>登录和
创建帐户
,其中
登录
位于屏幕中央,
创建帐户
位于屏幕正下方

我现在只有
创建帐户
按钮,它位于屏幕的顶部,而不是中央。由于某些原因,
登录
在任何地方都不会出现。有人能看一下我的XML文档,看看他们是否能发现发生这种情况的原因吗

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:padding="25dp"
android:layout_height="match_parent">

<Button
    android:id="@+id/bSignIn"
    android:text="SignIn"
    android:layout_centerHorizontal="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<Button
    android:id="@+id/bCreateAccount"
    android:text="Create Account"
    android:layout_centerHorizontal="true"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

</RelativeLayout>

哦,这是主要的活动(如果有关联的话)。非常感谢您的帮助

使用以下命令:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:padding="25dp"
    android:layout_height="match_parent">
    <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true">
    <Button
        android:id="@+id/bSignIn"
        android:text="SignIn"
        android:layout_centerHorizontal="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/bCreateAccount"
        android:text="Create Account"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/bSignIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
     />
    </RelativeLayout>
    </RelativeLayout>

使用以下方法:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:padding="25dp"
    android:layout_height="match_parent">
    <RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true">
    <Button
        android:id="@+id/bSignIn"
        android:text="SignIn"
        android:layout_centerHorizontal="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/bCreateAccount"
        android:text="Create Account"
        android:layout_centerHorizontal="true"
        android:layout_below="@+id/bSignIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
     />
    </RelativeLayout>
    </RelativeLayout>

您应该添加一个包装器,根据基本布局使用
android:layout\u centerInParent
。在这里面,你可以“安卓:下面的布局”来实现你想要的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:padding="25dp"
         android:layout_height="match_parent">

        <RelativeLayout
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
               <Button
                   android:id="@+id/bSignIn"
                   android:text="SignIn"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content" />

               <Button
                   android:id="@+id/bCreateAccount"
                   android:text="Create Account"
                   android:layout_below="@id/bSignIn"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content" />
        </RelativeLayout>
</RelativeLayout>

您应该添加一个包装器,根据基本布局使用
android:layout\u centerInParent
。在这里面,你可以“安卓:下面的布局”来实现你想要的

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         android:orientation="vertical"
         android:layout_width="match_parent"
         android:padding="25dp"
         android:layout_height="match_parent">

        <RelativeLayout
            android:layout_centerInParent="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
               <Button
                   android:id="@+id/bSignIn"
                   android:text="SignIn"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content" />

               <Button
                   android:id="@+id/bCreateAccount"
                   android:text="Create Account"
                   android:layout_below="@id/bSignIn"
                   android:layout_width="match_parent"
                   android:layout_height="wrap_content" />
        </RelativeLayout>
</RelativeLayout>

android:gravity=“center\u vertical”
设置为
RelativeLayout
,并将
android:layout\u lower=“@+id/bSignIn”
设置为您的
b创建帐户

这是密码

    <RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:gravity="center_vertical"
     android:layout_height="match_parent">

    <Button
     android:id="@+id/bSignIn"
     android:text="SignIn"
     android:layout_width="match_parent"
     android:layout_height="wrap_content" />

    <Button
     android:id="@+id/bCreateAccount"
     android:text="Create Account"
     android:layout_below="@+id/bSignIn"
     android:layout_width="match_parent"
     android:layout_height="wrap_content" />

   </RelativeLayout>

android:gravity=“center\u vertical”
设置为
RelativeLayout
,并将
android:layout\u lower=“@+id/bSignIn”
设置为您的
b创建帐户

这是密码

    <RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:orientation="vertical"
     android:layout_width="match_parent"
     android:gravity="center_vertical"
     android:layout_height="match_parent">

    <Button
     android:id="@+id/bSignIn"
     android:text="SignIn"
     android:layout_width="match_parent"
     android:layout_height="wrap_content" />

    <Button
     android:id="@+id/bCreateAccount"
     android:text="Create Account"
     android:layout_below="@+id/bSignIn"
     android:layout_width="match_parent"
     android:layout_height="wrap_content" />

   </RelativeLayout>

尝试以下代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:padding="25dp"
    android:layout_height="match_parent">

    <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true">

        <Button
        android:id="@+id/bSignIn"
        android:text="SignIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

        <Button
        android:id="@+id/bCreateAccount"
        android:text="Create Account"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
</RelativeLayout>

尝试以下代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:padding="25dp"
    android:layout_height="match_parent">

    <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true">

        <Button
        android:id="@+id/bSignIn"
        android:text="SignIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

        <Button
        android:id="@+id/bCreateAccount"
        android:text="Create Account"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>
</RelativeLayout>

只需添加:

android:layout_below="@id/bSignIn"
并将
centerHorizontal
更改为
centerInParent

bCreateAccount
按钮XML中,将其放置在前面的下方。

只需添加:

android:layout_below="@id/bSignIn"
并将
centerHorizontal
更改为
centerInParent

bCreateAccount
按钮XML中,将其放置在前面的下方。

尝试此操作

<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">

    <Button
        android:id="@+id/bSignIn"
        android:text="SignIn"
        android:layout_centerInParent="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/bCreateAccount"
        android:text="Create Account"
        android:layout_below="@+id/bSignIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</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">

    <Button
        android:id="@+id/bSignIn"
        android:text="SignIn"
        android:layout_centerInParent="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/bCreateAccount"
        android:text="Create Account"
        android:layout_below="@+id/bSignIn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>