How can i align the “LoginBox” LinearLayout to its parent (that is a RelativeLayout) both at left/right and bottom? I tried to insert:
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
but it doesn’t do the trick! Infact the linearlayout is not properly aligned to the margin of the screen! 🙁
This is my XML code:
<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>
Thank you in advance!
EDIT:
The first screen is what i have now! While the second, edited with photoshop (sorry), is what i want to get!
3
Answers
Try this:
I put a LinearLayout before the button, and added android:gravity=”bottom” to the LinearLayout. This should do it.
Remove your top layout’s right, left and bottom padding:
Remove
these lines form your outermost ReletiveLayout.
Thats it!