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.
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.
It's under Advanced Settings>Accessibility button>Select actions.
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.
You can do it with RelativeLayout
although you can also achieve that using FrameLayout
(like in the example in your the link).
In FrameLayout
Set 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With