简体   繁体   English

带有片段的Android Google Maps

[英]Android Google Maps with Fragment

I created a new Blank Activity with fragment in Android Studio and I need to include Google Map using SupportMapFragment. 我在Android Studio中使用片段创建了一个新的空白活动,并且需要使用SupportMapFragment包含Google Map。 On the top of the layout, I want to keep the toolbar, which shows the activity name by default. 在布局的顶部,我要保留工具栏,该工具栏默认显示活动名称。 How to do it or is there any tutorial? 怎么做还是有教程吗?

Yes there is a tutorial explaining it well here: http://www.truiton.com/2013/05/android-supportmapfragment-example/ 是的,这里有一个教程对此进行了很好的解释: http : //www.truiton.com/2013/05/android-supportmapfragment-example/

But to to keep the toolbar just add this in your xml activity (not as tutorials says), instead of modifying it completely, as you may have your toolbar defined in your xml, like this: 但是要保留工具栏,只需将其添加到您的xml活动中(而不是如教程所述),而不是对其进行完全修改,因为您可能在xml中定义了工具栏,如下所示:

<RelativeLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

On the tools:context add your activity class name with a preceding . 在tools:context上,在活动类名称前添加。 (dot). (点)。

Adjust the width and height of the relative layout to match your needs. 调整相对布局的宽度和高度,以满足您的需求。 Eg 200dp or leave them match_parent. 例如200dp或将其保留为match_parent。

If you need any more help let me know. 如果您需要更多帮助,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM