android的布局问题

时间:2013-07-16 01:43:36

标签: android xml

所以我正在为我的Android应用程序的登录和注册页面工作,我正在尝试实现这种布局,但我无法让它正常工作。

我正在寻找的所需布局是这样的。

desired layout

背景图片覆盖整个屏幕,然后右上角有一个按钮,中间底部有一个按钮。

但这是我从实现设计中获得的

current layout

这就是我在布局文件中写下的内容

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true" android:alwaysDrawnWithCache="false"
    android:layout_gravity="center">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:scaleType="center"
        android:layout_alignParentTop="true" android:src="@drawable/nyork2"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="top" >

        <Button
        android:id="@+id/register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="@string/button_register"

        />
     <Button
        android:id="@+id/login"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:text="@string/button_login"

        />
    </LinearLayout>





</RelativeLayout>

2 个答案:

答案 0 :(得分:2)

这应该有帮助

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true" android:alwaysDrawnWithCache="false"
    android:layout_gravity="center">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:scaleType="center"
        android:layout_alignParentTop="true" android:src="@drawable/nyork2"/>
    <Button
            android:id="@+id/register"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:text="@string/button_register" />

    <Button
            android:id="@+id/login"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="@string/button_login"/>

</RelativeLayout>

答案 1 :(得分:0)

删除线性布局,以便将按钮放在您想要的位置