Android 中心垂直圆';我不能处理碎片

Android 中心垂直圆';我不能处理碎片,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,我制作了一个包含两个编辑文本的简单片段。然后,我尝试添加一个图像按钮。我想让这个片段成为活动的中心,而且效果很好。但是,图像按钮不会位于两个编辑文本下面的片段中心。为什么centerVertical不能处理碎片? 以下是登录视图xml文件的xml代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

我制作了一个包含两个编辑文本的简单片段。然后,我尝试添加一个图像按钮。我想让这个片段成为活动的中心,而且效果很好。但是,图像按钮不会位于两个编辑文本下面的片段中心。为什么centerVertical不能处理碎片? 以下是登录视图xml文件的xml代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
 >
<EditText
    android:hint="Type username"
    android:id="@+id/userNameText"
    android:imeOptions="actionDone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
<EditText
    android:hint="Type Password"
    android:id="@+id/passwordText"
    android:layout_below="@id/userNameText"
    android:imeOptions="actionDone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
 <ImageButton
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/login"
     android:onClick="onClick"
     android:id="@+id/logInBtn"
     android:layout_below="@id/passwordText"
     android:layout_centerVertical="true"/>
 </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"
tools:context="com.example.bazar.MainActivity">
<fragment 
android:name="com.example.bazar.LogIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>

和主xml文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
 >
<EditText
    android:hint="Type username"
    android:id="@+id/userNameText"
    android:imeOptions="actionDone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
<EditText
    android:hint="Type Password"
    android:id="@+id/passwordText"
    android:layout_below="@id/userNameText"
    android:imeOptions="actionDone"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
 <ImageButton
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/login"
     android:onClick="onClick"
     android:id="@+id/logInBtn"
     android:layout_below="@id/passwordText"
     android:layout_centerVertical="true"/>
 </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"
tools:context="com.example.bazar.MainActivity">
<fragment 
android:name="com.example.bazar.LogIn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>

将main.xml中片段的布局参数更改为

android:layout_width="match_parent"
android:layout_height="match_parent"
编辑:

将您的登录布局更改为此(除了@ChrisS所说的内容外,还将进行此更改):



Sorry但这不起作用,它给出了一个错误:error:error:String type not allowed(在'layout\u height'处,值为'match\u content')。@chrissorry那是我的复制/粘贴fubar,改为正确读取也不起作用的
match\u parent
,现在小部件已经移动到屏幕@chriss的左上角,因为您没有为登录视图xml中的元素指定任何对齐方式,所以它们默认为角落。