0

I am trying to align a text area with username and phone along with a button to the bottom of the screen by adding margin-top on id with

android:id="@+id/textView1"

attribute but no effect as shown in the following snippet

 <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"
   >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:src="@drawable/ic_launcher"
         />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/phone"
        android:layout_centerVertical="true"
        android:text="Username"
         />

    <EditText
        android:id="@+id/username"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:ems="10" />

    <TextView
        android:id="@+id/TextView01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/username"
        android:layout_below="@+id/username"
        android:text="Phone No" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="16dp"
        android:gravity="center"
        android:text=" User Registration"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/phone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/TextView01"
        android:layout_centerHorizontal="true"
        android:ems="10"/>

    <Button
        android:id="@+id/register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/phone"
        android:layout_below="@+id/phone"
        android:text="Register" />


</RelativeLayout>

The screen below shows the output

enter image description here

I want from the username textview down to the register button to be align to the bottom of the screen. I have tried adding margin but did not work

Matei Radu
  • 2,038
  • 3
  • 28
  • 45
Blaze
  • 2,269
  • 11
  • 40
  • 82
  • Possible duplicate of [How to align views at the bottom of the screen?](http://stackoverflow.com/questions/2386866/how-to-align-views-at-the-bottom-of-the-screen) – dragi May 13 '16 at 16:25
  • @helleye my question is centered around margin – Blaze May 13 '16 at 16:44
  • If you want to use only margins, then you should know the height of each screen your application runs on, as well as the sum of the heights of each View you want to align at the bottom. The Android approach of dealing with this issue is with RelativeLayout. – dragi May 13 '16 at 16:51
  • I am surprised this is coming from you after marking my question as duplicate – Blaze May 13 '16 at 16:55
  • If you have the answer to the question you suggested please show me – Blaze May 13 '16 at 17:02
  • The answer is by using RelativeLayout and you can see how it is done if you open the linked question (duplicated one). – dragi May 13 '16 at 18:09

1 Answers1

0

Did you try to use a relative layout. If you have a relative layout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen.

Shridutt Kothari
  • 7,326
  • 3
  • 41
  • 61