Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android floating buttons over a view

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.

like image 772
Thebestshoot Avatar asked May 11 '12 12:05

Thebestshoot


People also ask

How do I keep the button on the bottom of my screen android?

How do I keep the button on the bottom of my screen Android? Make the Parent of the LinearLayout containing the button as relative and set the property of linear layout containing two buttons as android:layout_alignParentBottom="true". You can also set the gravity of the Linear Layout to Bottom. Save this answer.

How do I get rid of the floating home button on android?

It's under Advanced Settings>Accessibility button>Select actions.


2 Answers

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.

like image 54
Thommy Avatar answered Sep 26 '22 12:09

Thommy


You can do it with RelativeLayout although you can also achieve that using FrameLayout (like in the example in your the link). In FrameLayoutSet a proper gravity to the the buttons (Gravity.BOTTOM|Gravity.RIGHT, or via XML...), and in RelativeLayout set the reuiqred rules to the Buttons:

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

etc.

like image 37
avimak Avatar answered Sep 24 '22 12:09

avimak