簡體   English   中英

android:layout_alignParentRight =“ true”-editText仍出現在布局的左側-Android / XML

[英]android:layout_alignParentRight=“true” - editText still appears on the left of the layout - Android / XML

我有一個帶有兩個editText字段的RelativeLayout,我試圖與屏幕的右側對齊。 我所看到的以及我記得的android:layout_alignParentRight =“ true”應該可以解決問題,但是由於某些原因,它們仍然出現在屏幕的左側。

在此處輸入圖片說明

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/firstName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="First Name"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/lastName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Last Name"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Email Address"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:hint="Phone Number"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/userName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@null"
        android:ems="10"
        android:hint="USERNAME"
        android:inputType="textPersonName"
        android:textColor="#000000" />

    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null"
        android:ems="10"
        android:hint="PASSWORD"
        android:inputType="textPassword"
        android:textColor="#000000" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:background="@null"
            android:text="" />
    </LinearLayout>

    <Button
        android:id="@+id/submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Submit" />

</RelativeLayout>

編輯:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="20dp"

    android:scaleType="fitXY" 
    android:gravity="center_vertical"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/firstName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="First Name"
        android:inputType="textPersonName" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/lastName"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Last Name"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/email"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="Email Address"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:ems="10"
        android:hint="Phone Number"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/userName"
        android:layout_width="15dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:background="@null"
        android:ems="10"
        android:textColor="@color/black"
        android:hint="USERNAME"
        android:inputType="textPersonName" />

    <EditText
        android:id="@+id/password"
        android:layout_width="15dp"
        android:layout_height="wrap_content"
        android:background="@null"
        android:ems="10"
        android:textColor="@color/black"
        android:hint="PASSWORD"
        android:inputType="textPassword" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.5"
            android:background="@null"
            android:text="" />
    </LinearLayout>

    <Button
        android:id="@+id/submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Submit" />

</RelativeLayout>

編輯后外觀:

在此處輸入圖片說明

editTexts的寬度為match_parent,其文本在左側對齊。 因此,即使編輯文本在右側,也從左側開始(因為它填充了其父級的寬度)。 將寬度更改為較小的值,您將看到代碼有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM