与自定义布局SupportMapFragment,可能吗? [英] SupportMapFragment with a custom layout, possible?

查看:112
本文介绍了与自定义布局SupportMapFragment,可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有SupportMapFragment与自定义布局,现在下面code工作:

  @覆盖
公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){
        super.onCreateView(充气器,容器,savedInstanceState);
        查看查看= super.onCreateView(充气器,容器,savedInstanceState);
        // initMap();
        返回视图。
    }

但我想改变 onCreateView()方法膨胀,而不是调用 super.onCreateView()方法。
看起来像这样的:

 查看= inflater.inflate(R.layout.fragment,集装箱,FALSE);
MMAP =(GoogleMap的)view.findViewById(R.id.mapview);

但GoogleMap的不是视图所以我的不能将其添加到XML,如下列方式:

 < com.google.android.gms.maps.GoogleMap
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@ + ID /图形页面
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    />


解决方案

如果你想创建一个自定义布局的SupportMapFragment,我preFER延长 android.support.v4.app .Fragment 从支持库,并与 com.google.android.gms.maps.MapView 等观点夸大你的自定义XML那里。

但要小心转发的LiveCycle方法,这个图形页面引<一个href=\"https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapView\">here.

I am trying to have SupportMapFragment with a custom layout, right now the following code works :

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        View view = super.onCreateView(inflater, container, savedInstanceState);
        // initMap();
        return view;
    }

But I want to change the onCreateView() method to inflate a different layout, instead of calling the super.onCreateView() method. To look like something like this:

View view  = inflater.inflate(R.layout.fragment, container,false);
mMap = (GoogleMap)view.findViewById(R.id.mapview);

But GoogleMap is not a view so I cannot add it to the xml, like the following way:

<com.google.android.gms.maps.GoogleMap
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />

解决方案

If you want to create a SupportMapFragment with a custom layout, I prefer to extend the android.support.v4.app.Fragment from the Support Library and inflate your custom XML with the com.google.android.gms.maps.MapView and other views there.

But be careful to forward the livecycle methods to this MapView as quoted here.

这篇关于与自定义布局SupportMapFragment,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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