![](/img/trans.png)
[英]android:layout_alignParentRight=“true” does nothing
[英]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.