Android中級篇之百度地圖SDK v3.5.0-FragmentMap地圖架構[圖解SupportMapFragment類],androidsdk安裝圖解

來源:互聯網
上載者:User

Android中級篇之百度地圖SDK v3.5.0-FragmentMap地圖架構[圖解SupportMapFragment類],androidsdk安裝圖解
建立一個基於Fragment的地圖架構

  • SupportMapFragment

    SupportMapFragment 類,管理地圖生命週期。

  • 構造器概要

    構造器和說明:

    SupportMapFragment() 建構函式

  • 方法概要
    限定符和類型 方法 說明
    BaiduMap getBaiduMap() 擷取百度地圖控制器,當執行完 onCreateView 函數之後調用,否則返回 null.
    MapView getMapView() 擷取百度地圖控制項
    static SupportMapFragment newInstance() 建立一個MapFragment執行個體
    static SupportMapFragment newInstance(BaiduMapOptions options) 根據給定的百度地圖選項建立一個SupportMapFragment 執行個體
    void onActivityCreated(Bundle savedInstanceState) *
    void onAttach(Activity activity) *
    void onConfigurationChanged(Configuration newConfig) 當配置發送改變的時候會被調用
    void onCreate(Bundle savedInstanceState) *
    View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) *
    void onDestroy() *
    void onDestroyView() *
    void onDetach() *
    void onPause() *
    void onResume() *
    void onSaveInstanceState(Bundle outState) *
    void onStart() *
    void onStop() *
    void onViewCreated(View view, Bundle savedInstanceState) *
    void onViewStateRestored(Bundle savedInstanceState) *
  • MapFragment的使用

    建立 activity_fragment.xml :

    <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical">    <FrameLayout        android:id="@+id/fm_map"        android:layout_width="match_parent"        android:layout_height="match_parent"></FrameLayout></LinearLayout>

    建立 MapFragmentDemo 類繼承 BaseActivity

    public class MapFragmentDemo extends BaseActivity {    private SupportMapFragment map;    private FragmentManager fm;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_fragment);        //overlook:俯視角;zoom:縮放        MapStatus ms = new MapStatus.Builder().overlook(-20).zoom(15).build();        //compassEnabled是否開啟指南針;zoomControlsEnabled:是否按比例縮放;        BaiduMapOptions bo = new BaiduMapOptions().mapStatus(ms).compassEnabled(false).zoomControlsEnabled(false);        map = SupportMapFragment.newInstance(bo);        fm = getSupportFragmentManager();        fm.beginTransaction().add(R.id.fm_map, map, "map_fragemnt").commit();    }}

    運行:

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.