【发布时间】:2016-01-20 04:16:03
【问题描述】:
如果您注意到电子邮件和密码的 EditText 视图,则该行未居中。在 Android Studio 的设计和预览模式中,它们看起来是居中的,但是当我在手机上运行它时,就会出现这种情况。我很难让它居中。这是我目前的代码:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/email"
android:id="@+id/emailTextLabel"
android:layout_marginTop="42dp"
android:layout_alignParentTop="true"
android:layout_alignLeft="@+id/passwordTextLabel"
android:layout_alignStart="@+id/passwordTextLabel"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/password"
android:id="@+id/passwordTextLabel"
android:layout_marginLeft="27dp"
android:layout_marginStart="27dp"
android:layout_marginTop="50dp"
android:layout_below="@+id/emailTextLabel"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<EditText
android:layout_width="325dp"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/emailEditText"
android:layout_below="@+id/emailTextLabel"
android:layout_alignLeft="@+id/emailTextLabel"
android:layout_alignStart="@+id/emailTextLabel"/>
<EditText
android:layout_width="325dp"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="@+id/passwordEditText"
android:layout_below="@+id/passwordTextLabel"
android:layout_alignLeft="@+id/passwordTextLabel"
android:layout_alignStart="@+id/passwordTextLabel"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/keep_me_signed_in"
android:id="@+id/keepMeSignedInCheckBox"
android:layout_below="@+id/passwordEditText"
android:layout_alignLeft="@+id/passwordEditText"
android:layout_alignStart="@+id/passwordEditText"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sign_in"
android:id="@+id/sign_in_button"
android:layout_alignTop="@+id/sign_up_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="90dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sign_up"
android:id="@+id/sign_up_button"
android:layout_marginTop="40dp"
android:layout_below="@+id/keepMeSignedInCheckBox"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="90dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/use_without_account"
android:id="@+id/use_without_account_button"
android:layout_marginTop="8dp"
android:layout_below="@+id/sign_in_button"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
【问题讨论】:
标签: android xml android-relativelayout