如何在Google地图上显示浮动视图,就像Google地图中的搜索栏一样 [英] how to show a floating view on google map just like the search bar in Google Maps

查看:141
本文介绍了如何在Google地图上显示浮动视图,就像Google地图中的搜索栏一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功实现了map,但是我找不到任何有关这方面的帮助,这里是我的谷歌地图片段的实现

I have implemented map successfully, but I couldn't find any help regarding this here is my implementation of google map fragment

SupportMapFragment fragment;
    private GoogleMap map;
    FragmentManager fm;

@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        FragmentManager fm = getChildFragmentManager();
        fragment = (SupportMapFragment) fm.findFragmentById(R.id.mapLarge);
        if (fragment == null) {
            fragment = SupportMapFragment.newInstance();
            fragment.setRetainInstance(true);
            fm.beginTransaction().replace(R.id.mapLarge, fragment).commit();

        }

    }

@Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        if (map == null) {
            System.out.println("map is null");
            map = fragment.getMap();
  }

我以编程方式添加地图片段(解决方法是在Actionbar中显示mapview。 Tab)
任何帮助将不胜感激!

I am adding map fragment programatically (a work around to show mapview in Actionbar.Tab) any help will be appreciated !

推荐答案

这是我的答案,它可以帮助某人。我所做的是将工具栏放置在 CoordinatorLayout 中,并将一些余量应用于 AppBarLayout

Here is my answer, it may help someone. What I did is placed toolbar inside CoordinatorLayout and applied some margin to AppBarLayout.

<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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MapActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"
    android:theme="@style/AppTheme.AppBarOverlay">

    <include layout="@layout/toolbar" />

</android.support.design.widget.AppBarLayout>

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    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.CoordinatorLayout>

以下是上述代码的输出。

Below is the output of above code.

这篇关于如何在Google地图上显示浮动视图,就像Google地图中的搜索栏一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆