TextView и EdidText не выравниваются, как ожидалось

Итак, я пытаюсь сделать простую регистрацию, но мои представления выровнены не так, как ожидалось.

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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.mylifeinformationsharedsocial.SignUpActivity" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/username_id"
    android:text="@string/username_text"
    android:textSize="20sp"
    />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/username_edit_text_id"
    android:hint="@string/username_hint_texts"
    android:layout_toRightOf="@id/username_id"
    android:layout_toEndOf="@id/username_id"
    />

 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/password_id"
    android:text="@string/password_text"
    android:textSize="20sp"
    android:layout_below="@id/username_edit_text_id"
    />

<EditText
    android:id="@+id/password_edit_text_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:hint="@string/passworde_hint_texts"
    android:layout_toRightOf="@id/password_id"
    android:layout_toEndOf="@id/password_id"
    android:layout_below="@id/username_edit_text_id"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/email_id"
    android:text="@string/email_text"
    android:textSize="20sp"
    android:layout_below="@id/password_id"
    />

<EditText
    android:id="@+id/email_edit_text_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:hint="@string/email_hint_text"
    android:layout_toRightOf="@id/email_id"
    android:layout_toEndOf="@id/email_id"
    android:layout_below="@id/password_edit_text_id"
    />

<Button
    android:id="@+id/sign_up_button_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/sign_up_button_text"
    android:layout_below="@id/email_id"
    />

Graphical Layout:

введите здесь описание изображения

Кажется, я не могу найти, что с ним не так. Любая помощь будет очень признательна. Проблема в том, что электронная почта направлена ​​вниз, как показано на рисунке. Его довольно пролив вперед, но, по-видимому, нет.


person God    schedule 14.08.2015    source источник
comment
Используйте LinearLayout для лучшего выравнивания.   -  person Rubanraj Ravichandran    schedule 14.08.2015
comment
@Rubanraj Я знал, что этот ответ придет, ХА-ХА. Я хочу сделать это с относительным расположением.   -  person God    schedule 14.08.2015
comment
Спасибо, приятель.. :-) ты меня понял.. @God   -  person Rubanraj Ravichandran    schedule 14.08.2015


Ответы (2)


Ваш password_text объявляется ниже username_edit_text_id, тогда как он хочет быть ниже username_id.

Android берет все спецификации, которые вы ему даете, и делает все возможное, чтобы выполнить то, что вы просили, но если спецификации несовместимы или их невозможно удовлетворить, то это будет не так.

person chiastic-security    schedule 14.08.2015
comment
Это не помогло, но ты был прав. Я думаю, что не могу сделать это с относительным расположением. Я перейду на LineaLayout. Спасибо. - person God; 14.08.2015

Может быть, вы могли бы попробовать это так:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/username_id"
    android:text="@string/username_text"
    android:textSize="20sp"
    />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/username_edit_text_id"
    android:hint="@string/username_hint_texts"
    android:layout_toRightOf="@id/username_id"
    android:layout_toEndOf="@id/username_id"
    />

 <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/password_id"
    android:text="@string/password_text"
    android:textSize="20sp"
    android:layout_below="@id/username_edit_text_id"
    />

<EditText
    android:id="@+id/password_edit_text_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPassword"
    android:hint="@string/passworde_hint_texts"
    android:alignRight = "@id/username_edit_text_id"
    android:layout_below="@id/username_edit_text_id"
    />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/email_id"
    android:text="@string/email_text"
    android:textSize="20sp"
    android:layout_below="@id/password_id"
    />

<EditText
    android:id="@+id/email_edit_text_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textEmailAddress"
    android:hint="@string/email_hint_text"
    android:alignRight = "@id/password_edit_text_id"
    android:layout_below="@id/password_edit_text_id"
    />

<Button
    android:id="@+id/sign_up_button_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/sign_up_button_text"
    android:layout_below="@id/email_id"
    />

Вместо toRightOf я использовал alignRight, чтобы все EditText были выровнены по правому краю.

Это будет хорошо работать для вашего случая (если у вас есть только эти строки), в противном случае вы должны выровнять все EditText по правому краю.

person Gent Ahmeti    schedule 15.08.2015