Не могу поместить кнопку внизу с layout_gravity в LinearLayout - PullRequest
0 голосов
/ 21 октября 2018

Я только начал программировать Android и хочу создать страницу регистрации, но я не могу поставить снизу вниз с layout_gravity.Я установил ориентацию: вертикальную, но она не работает.У кого-нибудь есть идеи?Я буду очень признателен, если кто-нибудь поможет мне исправить это.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="vertical"

>



    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter Your Username"
            android:textColor="@android:color/darker_gray"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"



    />
    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter Your Email"
            android:textColor="@android:color/darker_gray"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"

    />

    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Password"
            android:textColor="@android:color/darker_gray"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"

    />
    <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Confirm Password"
            android:textColor="@android:color/darker_gray"
            android:layout_marginRight="15dp"
            android:layout_marginLeft="15dp"

    />


    <Button
            android:text="Register"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"

    />

</LinearLayout>

1 Ответ

0 голосов
/ 21 октября 2018

A RelativeLayout - простое решение в этих случаях, потому что для достижения того, что вы хотите, требуется только этот атрибут:

android:layout_alignParentBottom="true"

как и для других EditTexts, я дал имкаждый идентификатор и выровнен каждый под другим:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Your Username"
        android:textColor="@android:color/darker_gray"
        android:layout_alignParentTop="true"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp" />

    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Enter Your Email"
        android:layout_below="@id/editText1"
        android:textColor="@android:color/darker_gray"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp" />

    <EditText
        android:id="@+id/editText3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:layout_below="@id/editText2"
        android:textColor="@android:color/darker_gray"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp" />

    <EditText
        android:id="@+id/editText4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="Confirm Password"
        android:layout_below="@id/editText3"
        android:textColor="@android:color/darker_gray"
        android:layout_marginRight="15dp"
        android:layout_marginLeft="15dp"/>


    <Button
        android:text="Register"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_alignParentBottom="true"/>

</RelativeLayout>
...