2016-05-13 106 views
0

我试图通过增加对ID的margin-top与在一个相对布局屏幕的底部对齐意见

android:id="@+id/textView1" 
对准用户名和手机,一个按钮在屏幕的底部沿着文本区域

属性,但如下面的片段所示没有影响

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

下面的屏幕显示的输出

enter image description here

我希望从用户名textview下注册按钮,以对齐屏幕的底部。我已尝试添加保证金,但没有工作

+0

可能重复的[如何在屏幕底部对齐视图?](http://stackoverflow.com/questions/2386866/how-to-align-views-at-the-bottom-of-the-屏幕) – helleye

+0

@helleye我的问题是围绕保证金 – Blaze

+0

如果你只想使用保证金,那么你应该知道你的应用程序运行的每个屏幕的高度,以及你想要对齐的每个视图的高度总和底端。处理这个问题的Android方法是使用RelativeLayout。 – helleye

回答

0

您是否尝试使用相对布局。 如果你有一个填充整个屏幕的相对布局,你应该可以使用android:layout_alignParentBottom将按钮移动到屏幕的底部。

+0

是的,我用了一个相对的布局 – Blaze

+0

请发布完整的XML,并张贴预期的图像,所以问题可以更清晰 –

+0

我已经添加完整的XML。我想从用户名textview下到注册按钮来对齐屏幕的底部 – Blaze