简体   繁体   English

将相对布局中的视图与屏幕底部对齐

[英]Align views in a relative layout to the bottom of the screen

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 我正在尝试通过在ID上添加margin-top来将带有用户名和电话的文本区域以及一个按钮对齐到屏幕底部

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 下面的屏幕显示输出

在此处输入图片说明

I want from the username textview down to the register button to be align to the bottom of the screen. 我希望从用户名textview到注册按钮与屏幕底部对齐。 I have tried adding margin but did not work 我曾尝试增加保证金,但是没有用

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. 如果您的相对布局会占据整个屏幕,那么您应该可以使用android:layout_alignParentBottom将按钮移至屏幕底部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM