Android floating buttons over a view

android, android-layout, android-view

Solution

You can achive that with a `RelativeLayout`:

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

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    </ListView>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="15dp"
        android:layout_marginRight="15dp"
        android:text="Button" />
</RelativeLayout>

Note that the last added Widget is on top.

Problem

I was trying to have a floating button on my view, I googled and found this link which pretty well sums it up. http://www.jondev.net/articles/Floating_Views_in_Android_(Buttons) While this is true for one button, but what if i want to have two floating buttons one at "top left" and another at "bottom right". I thought of having a relative layout which has two buttons with lay out gravities different. Will this work. I tried it and miserably failed. Has any one else tried to do this? Is there any way of doing this, if so please let me know.

Original source