Android : MapView in a CollapsingToolbarLayout -
i'm trying put map view
(or fragment containing map)inside collapsingtoolbarlayout
. want have parallax effect on when recyclerview
scrolls. unfortunately, isn't showing @ all! not grey grid! collapsing animation working though. i've search everywhere, able find imageview
, no other component. here questions :
- is possible put else
imageview
incollapsingtoolbarlayout
? (the documentation talking child views thought possible) - if so, fragment allowed well?
- then doing wrong??
here xml :
<android.support.design.widget.coordinatorlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:map="http://schemas.android.com/tools" android:id="@+id/main_content" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.appbarlayout android:id="@+id/appbarlayout" android:layout_width="match_parent" android:layout_height="300dp"> <android.support.design.widget.collapsingtoolbarlayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:contentscrim="?attr/colorprimary" app:expandedtitlemarginend="64dp" app:expandedtitlemarginstart="48dp" app:layout_scrollflags="scroll|exituntilcollapsed"> <android.support.v7.widget.toolbar android:id="@+id/main_activity_toolbar" android:layout_height="?attr/actionbarsize" android:layout_width="match_parent" android:background="?attr/colorprimary" android:layout_alignparenttop="true" app:layout_collapsemode="pin" app:theme="@style/themeoverlay.appcompat.dark.actionbar"> </android.support.v7.widget.toolbar> <com.google.android.gms.maps.mapview android:id="@+id/main_activity_mapview" android:layout_width="match_parent" android:layout_height="match_parent" android:apikey="aizasya-keukt39qk8eg7iywrifgsvkrzzz6zno" android:clickable="true" app:layout_collapsemode="parallax" /> </android.support.design.widget.collapsingtoolbarlayout> </android.support.design.widget.appbarlayout> <android.support.v7.widget.recyclerview android:id="@+id/main_rv_list_places" android:scrollbars="vertical" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </android.support.design.widget.coordinatorlayout>
and part map back.
onmapready
never triggered.
if (mmap == null) { mapview mapview = (mapview) findviewbyid(r.id.mapview); mapview.getmapasync(new onmapreadycallback() { @override public void onmapready(googlemap googlemap) { mmap = googlemap; mapsinitializer.initialize(mainactivity.this); //... // other stuff here } }); }
you can use mapview display google map.
within coordinator layout can use collapsing toolbar mapview . working fine.
need mention google map key correctly.
activity_main.xml:
<android.support.design.widget.coordinatorlayout 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.design.widget.appbarlayout android:id="@+id/appbar_lay" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ffffff" android:fitssystemwindows="true" android:theme="@style/themeoverlay.appcompat.dark.actionbar"> <android.support.design.widget.collapsingtoolbarlayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" app:contentscrim="?attr/colorprimary" app:layout_scrollflags="scroll|exituntilcollapsed" app:titleenabled="false" app:statusbarscrim="@null" android:fitssystemwindows="true"> <com.google.android.gms.maps.mapview android:id="@+id/map_view" android:layout_width="match_parent" android:layout_height="300dp" android:layout_below="@+id/main_lay" android:apikey="@string/google_maps_key" android:clickable="true" android:enabled="true" android:focusable="true" app:layout_collapsemode="parallax"/> </android.support.design.widget.collapsingtoolbarlayout> </android.support.design.widget.appbarlayout> <android.support.v7.widget.recyclerview android:id="@+id/post_rcycler" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#ffffff" android:visibility="visible" android:cliptopadding="false" android:fitssystemwindows="true" app:layout_collapsemode="parallax" app:layout_behavior="@string/appbar_scrolling_view_behavior"> </android.support.v7.widget.recyclerview> </android.support.design.widget.coordinatorlayout>
mainactivity.java:
public class mainactivity extends appcompatactivity implements view.onclicklistener, onmapreadycallback, googleapiclient.connectioncallbacks, googleapiclient.onconnectionfailedlistener, com.google.android.gms.location.locationlistener, googlemap.onmaploadedcallback { private mapview mapview; private googlemap mgooglemap; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mapview = (mapview) findviewbyid(r.id.map_view); mapview.oncreate(savedinstancestate); mapview.getmapasync(this); } @override public void onmapready(googlemap googlemap) { mgooglemap = googlemap; mapview.getmapasync(this); } }
Comments
Post a Comment