繁体   English   中英

在RelativeLayout问题中对齐LinearLayout

[英]Align LinearLayout inside a RelativeLayout issue

如何在左侧/右侧和底部将“ LoginBox” LinearLayout与其父级(即RelativeLayout)对齐? 我试图插入:

 android:layout_alignParentBottom="true"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"

但这并不能解决问题! 实际上,线性布局未正确对准屏幕的边缘! :(

这是我的XML代码:

<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"
    android:background="@drawable/sfondologin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

<ImageView
    android:id="@+id/imageView1"
   android:layout_width="200dp"
            android:layout_height="200dp"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/stemmatrasparente" />

<LinearLayout
    android:id="@+id/LoginBox"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <EditText
            android:id="@+id/usernametxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/sfondobuttonedittext"
            android:drawableLeft="@drawable/usericon"
            android:ems="10"
            android:gravity="center_horizontal|center"
            android:paddingLeft="15dp"
            android:imeOptions="actionNext"
            android:singleLine="true"
            android:textSize="18dp"
            android:typeface="sans" >

            <requestFocus />
        </EditText>

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.18" >
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

        <EditText
            android:id="@+id/passwordtxt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:background="@drawable/sfondobuttonedittext"
            android:drawableLeft="@drawable/lockicon"
            android:ems="10"
            android:gravity="center_vertical|center"
            android:inputType="textPassword"
            android:paddingLeft="15dp"
            android:imeOptions="actionDone"
            android:textSize="18dp"
            android:typeface="sans" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.29" >

        <TextView
            android:id="@+id/forgotpass"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="Dimenticato la password?"
            android:textColor="@color/white"
            android:textColorHint="@color/white"
            android:textSize="@dimen/value12dp" />

    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/loginbtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:background="@drawable/sfondobuttonlogin"
            android:text="Login"
            android:textColor="@color/white" />

    </RelativeLayout>

    <Button
        android:id="@+id/registerbtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center|end"
        android:background="@drawable/sfondobuttonrb2"
        android:text="Registrati"
        android:textColor="@color/white" />

</LinearLayout>
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_gravity="left"
    android:layout_weight="0.01" 
    android:background="#00000000">
</RelativeLayout>

</RelativeLayout>

先感谢您!

编辑:第一个屏幕是我现在拥有的! 而第二个是用photoshop编辑的(对不起),这是我想要的!

布局进行编辑布局已编辑

尝试这个:

<LinearLayout
        android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom">

<Button
        android:id="@+id/registerbtn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|center|end"
        android:background="@drawable/sfondobuttonrb2"
        android:text="Registrati"
        android:textColor="@color/white" />
</LinearLayout>

我在按钮前放置了LinearLayout,然后将android:gravity =“ bottom”添加到LinearLayout。 这应该做。

删除顶部布局的右侧,左侧和底部填充:

<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"
    android:background="@drawable/sfondologin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

去掉

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

这些行构成了最外面的ReletiveLayout。 而已!

暂无
暂无

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

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