图形页面中的片段(的Andr​​oid 4.0或更高版本) [英] MapView in Fragment ( Android 4.0 or higher)

查看:150
本文介绍了图形页面中的片段(的Andr​​oid 4.0或更高版本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找了一段时间发现与code例如一个很好的教程在片段的图形页面进行ICS。

I've been looking for a while to find a good tutorial with code example for a MapView in Fragment for ICS.

任何人有什么联系?

推荐答案

下面是一本书的样应用展示如何有一个图形页面片段在API等级11+的应用程序。这是大多只是一个 MapActivity 。下面是加载图形页面片段的键位

Here is a book's sample application showing how to have a MapView in a Fragment in an API Level 11+ app. It's mostly just a MapActivity. Here are the key bits of the fragment that loads the MapView:

public class MapFragment extends Fragment {
  private MapView map=null;
  private MyLocationOverlay me=null;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                            Bundle savedInstanceState) {
    return(new FrameLayout(getActivity()));
  }

  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    map=new MapView(getActivity(), "0mjl6OufrY-tHs6WFurtL7rsYyEMpdEqBCbyjXg");
    map.setClickable(true);

    map.getController().setCenter(getPoint(40.76793169992044,
                                            -73.98180484771729));
    map.getController().setZoom(17);
    map.setBuiltInZoomControls(true);

    Drawable marker=getResources().getDrawable(R.drawable.marker);

    marker.setBounds(0, 0, marker.getIntrinsicWidth(),
                            marker.getIntrinsicHeight());

    map.getOverlays().add(new SitesOverlay(marker));

    me=new MyLocationOverlay(getActivity(), map);
    map.getOverlays().add(me);

    ((ViewGroup)getView()).addView(map);
  }

  // rest of fragment here
}

这篇关于图形页面中的片段(的Andr​​oid 4.0或更高版本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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