I have an activity that includes a fragment, inside it I have a map using google maps api, and I want to add a bottom sheet which should automatically move up my location floating button until it reach a medium height.
Here is my fragment:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/my_location_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="66dp"
app:backgroundTint="#ffffff"
app:elevation="6dp"
app:layout_anchor="#id/mapView"
app:layout_anchorGravity="bottom|right|end"
app:pressedTranslationZ="12dp"
app:srcCompat="#drawable/ic_my_location_black_24dp" />
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#android:color/holo_blue_light"
app:behavior_hideable="false"
app:behavior_peekHeight="55dp"
android:clipToPadding="true"
app:layout_behavior="#string/bottom_sheet_behavior">
<FrameLayout
android:id="#+id/job_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="2dp" />
</android.support.v4.widget.NestedScrollView>
I want to archive something like that, look at the my location button:
https://www.youtube.com/watch?v=iwpR_uzqTq4
Try anchor your fab with your sheet and put the anchor gravity as top|right as follow
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="350dp"
android:background="#android:color/holo_blue_light"
app:behavior_hideable="false"
app:behavior_peekHeight="55dp"
android:clipToPadding="true"
app:layout_behavior="#string/bottom_sheet_behavior">
<FrameLayout
android:id="#+id/job_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="2dp" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/my_location_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="66dp"
app:backgroundTint="#ffffff"
app:elevation="6dp"
app:layout_anchor="#id/bottom_sheet"
app:layout_anchorGravity="top|end"
app:pressedTranslationZ="12dp"
app:srcCompat="#drawable/ic_my_location_black_24dp" />
</android.support.design.widget.CoordinatorLayout>
Related
The code on floating action menu is working but other floating action buttons are not displayed. I have a Google Map and a recyclerview below the map. It seems that the map is covering the other floating action buttons. Below is the code for the floating action button. I followed a youtube video for it.
<android.support.design.widget.CoordinatorLayout android:id="#+id/profilenav"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapView"
background="#FFF9C4"
android:orientation="vertical"
android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MapviewPage"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:id="#+id/mapview"
android:layout_width="match_parent"
android:layout_height="350dp"/>
<view class="android.support.v7.app.AlertController$RecycleListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical"
android:visibility="visible">
</view>
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="#dimen/fab_margin_right"
android:layout_marginBottom="16dp"
android:src="#drawable/menu"
android:elevation="6dp"
android:id="#+id/fab_nav"
app:pressedTranslationZ="12dp"
android:backgroundTint="#color/fab1_color"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="#dimen/fab_margin_right"
android:layout_marginBottom="100dp"
android:src="#drawable/settings"
android:elevation="6dp"
android:id="#+id/fab_settings"
app:pressedTranslationZ="12dp"
android:backgroundTint="#color/fab2_color"
android:visibility="invisible"/>
</android.support.design.widget.CoordinatorLayout>
The buttons should overlay on the Google Map and the recyclerview.
You have to add two more line in floating button.
<android.support.design.widget.CoordinatorLayout android:id="#+id/profilenav"
android:layout_width="match_parent"
android:layout_height="match_parent"
background="#FFF9C4"
android:orientation="vertical"
android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/test"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
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="350dp"
tools:context=".view.activities.TestMap" />
<view class="android.support.v7.app.AlertController$RecycleListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
android:visibility="visible">
</view>
</LinearLayout>
</ScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="#dimen/fab_margin_right"
android:layout_marginBottom="16dp"
android:src="#drawable/ic_check_circle_black_24dp"
android:elevation="6dp"
android:id="#+id/fab_nav"
app:pressedTranslationZ="12dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:backgroundTint="#color/color_type_help"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="#dimen/fab_margin_right"
android:layout_marginBottom="100dp"
android:src="#drawable/logo"
android:elevation="6dp"
android:id="#+id/fab_settings"
app:pressedTranslationZ="12dp"
app:layout_anchor="#id/test"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:backgroundTint="#color/translucent"
android:visibility="visible"/>
</android.support.design.widget.CoordinatorLayout>
three line add this in floating button.
app:layout_anchor="#id/test"
app:layout_anchorGravity="bottom|right|end"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
In my coordinator layout I included another layout which causes AppBarLayout to move to the top and positioned under the status bar,in other words the toolbar height is the half size of it's real height, why is this happening? And also the title of the toolbar is not positioning properly.
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ma_main">
<android.support.design.widget.AppBarLayout
android:id="#+id/ma_appbar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="#+id/ma_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/AppTheme.popup"/>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/main_activity_recycler"/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ma_fab"
app:layout_anchor="#id/ma_recycler_layout"
app:layout_anchorGravity="bottom|end"
android:layout_margin="15dp"
app:fabSize="normal"
android:src="#drawable/pencil"
android:elevation="8dp" />
</android.support.design.widget.CoordinatorLayout>
and included layout
<LinearLayout 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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:showIn="#layout/activity_main"
android:id="#+id/ma_recycler_layout">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/ma_recyclerView"
android:visibility="invisible">
</android.support.v7.widget.RecyclerView>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="2dp"
android:padding="5dp"
android:id="#+id/ma_progressbar"
android:visibility="visible"
android:indeterminate="true"
/></LinearLayout>
make some changes in xml like below ..
<RelativeLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.AppBarLayout
android:id="#+id/ma_appbar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
<android.support.v7.widget.Toolbar
android:id="#+id/ma_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/AppTheme.popup" />
</android.support.design.widget.AppBarLayout>
</RelativeLayout>
<include layout="#layout/rl" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/ma_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:elevation="8dp"
android:src="#drawable/pencil"
app:fabSize="normal"
app:layout_anchor="#id/ma_recycler_layout"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
then after recyler view layout like below ..
<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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:id="#+id/ma_recycler_layout">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/ma_recyclerView"
android:visibility="invisible">
</android.support.v7.widget.RecyclerView>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:padding="5dp"
android:id="#+id/ma_progressbar"
android:visibility="visible"
android:indeterminate="true"
android:layout_centerInParent="true"
/></RelativeLayout>
I have this problem to accommodate my floating button, and I do not understand why it does not work.
I would appreciate your response since I can not find the reason why this is happening, one more detail when scrolling or reloading the fragment some of the floating buttons will be accommodated.
And sorry for my English.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorBackground"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.CardView
android:id="#+id/mRequestCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="100dp"
android:orientation="horizontal"
app:cardBackgroundColor="#color/colorWhite"
app:cardCornerRadius="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="#+id/vDivisor"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorGreen" />
...
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="#dimen/fab_margin"
android:backgroundTint="#color/colorPurple"
android:scaleType="centerCrop"
android:src="#drawable/ic_route_direction"
app:layout_anchor="#id/mRequestCard"
app:layout_anchorGravity="right|end|bottom" />
</android.support.design.widget.CoordinatorLayout>
And this is my RecyclerView Which is inflated in a fragment
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.HistorialFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/mRecyclerRequest"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</FrameLayout>
And this is my fragment, where I show the RecyclerView
<FrameLayout 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/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.test.MainActivity"
tools:showIn="#layout/app_bar_main">
</FrameLayout>
you should try RelativeLayout like this
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorBlack"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="#dimen/activity_corner"
android:layout_marginBottom="#dimen/activity_margin">
<!--your cardview item here-->
</android.support.v7.widget.CardView>
</RelativeLayout>
for your RecyclerView item
Check if this helps you:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:orientation="vertical">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<android.support.v7.widget.CardView
android:id="#+id/mRequestCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:elevation="100dp"
android:orientation="horizontal"
app:cardBackgroundColor="#color/colorWhite"
app:cardCornerRadius="3dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:id="#+id/vDivisor"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#color/colorGreen" />
...
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:backgroundTint="#color/colorAccent"
android:scaleType="centerCrop"
android:src="#drawable/ic_launcher"
app:layout_anchor="#id/mRequestCard"
app:layout_anchorGravity="right|end|bottom" />
</RelativeLayout>
try this use RelativeLayout and make your FloatingActionButton property android:layout_alignParentBottom="true" and
android:layout_alignParentRight="true" like below code
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/colorBlack"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cardCornerRadius="#dimen/activity_corner"
android:layout_marginBottom="#dimen/activity_margin">
</android.support.v7.widget.CardView>
</RelativeLayout>
I want to Place floating action button on top of map fragment.
My map fragment is completely filled the entire screen. When I place a floating action button it is not coming on top of map fragment
Please refer the image attached:
Please find layout code here
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_small"
>
<fragment
android:id="#+id/autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<!--<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/bell32"
android:visibility="invisible"
/>
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/alarm_on_switch"
android:layout_gravity="right|top"
android:layout_marginRight="#dimen/margin_small"
android:drawableLeft="#drawable/bell32"
/>-->
</android.support.v7.widget.CardView>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
tools:context="reminder.locrem.com.locationreminder.MapsActivity"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_margin="16dp"
android:src="#drawable/done"
app:layout_anchorGravity="bottom|right|end"
app:elevation="4dp" />
</LinearLayout>
</ScrollView>
You can use FrameLayout to acieve what you want.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_small">
<fragment
android:id="#+id/autocomplete_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="reminder.locrem.com.locationreminder.MapsActivity" />
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_margin="16dp"
android:src="#drawable/done"
app:elevation="4dp"
app:layout_anchorGravity="bottom|right|end" />
</FrameLayout>
</LinearLayout>
</ScrollView>
Hi you can try to this code..
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="30dp"
android:background="#android:color/transparent"
android:clickable="true"
android:onClick="myLocationCall"
android:rotation="0" />
</RelativeLayout>
I had a similar requirement, I used android material floating action button.
The button came with material design.
The trick was to add the button inside the fragment and then change the margin gravity accordingly.
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
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="0dp"
android:layout_weight="1"
tools:context=".ui.Maps.MapsActivity" >
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/floatingActionButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_gravity="end|bottom"
android:layout_margin="8dp"
android:src="#android:drawable/ic_menu_revert" />
</fragment>
You just need to change the android:layout_gravity="top|right"
<android.support.design.widget.CoordinatorLayout
android:id="#+id/main_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="#+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|right"
android:layout_margin="16dp"
android:src="#drawable/ic_done"
app:layout_anchor="#id/lvToDoList"
app:layout_anchorGravity="bottom|right|end" />
</android.support.design.widget.CoordinatorLayout>
Good afternoon,
I am trying to put a FAB at the bottom|end of a fragment, but I do not know where I can place it.
Here is the Fragment's xml code :
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cars_list_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/scrollable_layout">
<include layout="#layout/write_comment"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
And the FAB :
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_plus" />
Thanks for your help !
An answer helped me to have a first "solution" with this code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cars_list_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/scrollable_layout">
<include layout="#layout/write_comment"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_plus"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
But it does not work correctly :
Try this:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/cars_list_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/scrollable_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/fab_margin"
android:src="#drawable/ic_photo_camera_white"
app:backgroundTint="#color/colorFabButton" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/image12"
android:layout_width="match_parent"
android:layout_height="250dp"
android:alpha="0.5"
android:src="#drawable/lawbook"
android:scaleType="fitXY"/>
<de.hdodenhof.circleimageview.CircleImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/profile_image"
android:layout_width="120dp"
android:layout_height="120dp"
android:src="#drawable/aliyar"
android:layout_above="#+id/text121"
android:layout_centerHorizontal="true"
android:layout_marginBottom="71dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/image12"
android:textSize="14sp"
android:layout_marginTop="40dp"
android:id="#+id/text121"
android:text="#string/aliyar1"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text121"
android:layout_marginTop="5dp"
android:textSize="14sp"
android:text="#string/aliyar2"
android:id="#+id/text122"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text122"
android:layout_marginTop="5dp"
android:text="#string/aliyar3"
android:textSize="14sp"
android:id="#+id/text123"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text123"
android:layout_marginTop="5dp"
android:text="#string/aliyar4"
android:id="#+id/text124"
android:textSize="14sp"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text124"
android:layout_marginTop="5dp"
android:text="#string/aliyar5"
android:id="#+id/text125"
android:textSize="14sp"
android:gravity="center_horizontal"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/text125"
android:layout_marginTop="5dp"
android:text="#string/aliyar6"
android:textSize="14sp"
android:id="#+id/text126"
android:gravity="center_horizontal"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Check below Layout :
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/contactnew">
<include
layout="#layout/contentcontact"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/facebookfab"
android:layout_gravity="bottom|right"
android:layout_width="299dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
app:backgroundTint="#fff"
android:src="#mipmap/facebook" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/callfab"
android:layout_gravity="bottom|left"
android:layout_width="299dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
app:backgroundTint="#color/Color_Blue"
android:src="#drawable/ic_local_phone_black_24dp" />
</android.support.design.widget.CoordinatorLayout>