0
我做了一個簡單的片段,其中有兩個編輯文本。然後,我試着添加一個圖像按鈕。我希望這個片段處於活動的中心,並且工作得很好。但是,圖像按鈕不會進入兩個編輯文本下面片段的中心。爲什麼不將中心垂直工作與片段結合? 這裏是登錄查看XML文件的XML代碼:centerVertical將無法與片段
<?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>
和主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"
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>
很抱歉,但沒有奏效,它給出了一個錯誤: 錯誤:錯誤:字符串類型不允許(在「layout_height」,值爲「match_content」)。 @ChrisS – samDroid
對不起,這是一個複製/粘貼在我的部分,改爲正確閱讀'match_parent' – ChrisStillwell
也沒有工作,現在的部件已經移動到屏幕的左上角@ChrisS – samDroid