Q:

Put a button to the right and middle of a layout

If I have a layout in xml as follow
<RelativeLayout
   <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_toLeftOf="@+id/bFb"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/etUserName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />

        <EditText
            android:id="@+id/etPass"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword"
            />

        <Button
            android:id="@+id/bLogin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Login" />
    </LinearLayout>
    <Button                       //This is the button on question
        android:id="@+id/bFb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/linearLayout1"
        android:text="Button" /> 

//there are more stuffs here below the linear layout
</RelativeLayout>

How can I have the button to the right of the linearlayout AND aligned at the middle of linear layout? I don't want the button borders to stretch the whole linear layout, just the middle of the linear layout
Thank you

A:

You can achieve what you want by changing RelativeLayout to LinearLayout and supply a weight for its first child like that
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <EditText
            android:id="@+id/etUserName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <EditText
            android:id="@+id/etPass"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
        <Button
            android:id="@+id/bLogin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Login" />
    </LinearLayout>
    <Button
        android:id="@+id/bFb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="Button" />
</LinearLayout>

Which will produce this 
EDIT
You can achieve it with relative layout that way 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:orientation="vertical" >
        <EditText
            android:id="@+id/etUserName"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <EditText
            android:id="@+id/etPass"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="textPassword" />
        <Button
            android:id="@+id/bLogin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Login" />
    </LinearLayout>
        <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:layout_toRightOf="@id/linearLayout1" >
        <Button
            android:id="@+id/bFb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:text="Button" />
    </LinearLayout>
</RelativeLayout>

But it needs some tweeks to produce the exact same thing, in my opinion LinearLayout's weight serve better in your case, so if I were in your shoe I choose the LinearLayout solution and wrap it in a RelativeLayout

