Nobody Nobody -4 years ago 105
Android Question

Flaoating Action button position

I tried adding the floating action button but just not able to get it to position in the expected place.I've the xml along with the obtained and expected image.

Actually I want two such floating action buttons one on top of the other.

MapsActivity

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/maplinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/AppTheme">


<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<fragment
android:id="@+id/place_autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<fragment xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.srinivas.democomplete.MapsActivity" />

</LinearLayout>


<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:clickable="true"
app:srcCompat="@android:drawable/ic_dialog_email"

/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
android:id="@+id/autoComplete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#303F9F"
android:text="Auto Complete"
android:textColor="#ffffff"
android:visibility="visible" />

<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:background="#ffffff" />

<Button
android:id="@+id/bsolarpanel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#303F9F"
android:text="Add solar panels"
android:textColor="#ffffff" />
</LinearLayout>


</RelativeLayout>

</RelativeLayout>


Current button position
Expected position

Any help would be great thx!

Answer Source

Just remove the line

android:layout_gravity="bottom|end"

You can use margin to set it according to your need

UPDATE

You can add some more attributes like

android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download