getSupportFragmentManager

getSupportFragmentManager

本文介绍了谷歌地图整合和SlidingMenu的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现谷歌地图v2和jfeinstein10的SliderMenu,我设法实现SliderMenu但当我想添加地图在活动中,我得到错误

使用GoogleMap地图=((SupportMapFragment)getSupportFragmentManager()。FindFragmentById(R.id.fragMapa))。的GetMap();

为getSupportFragmentManager更具体的()

对于任何解决方案集成两者。我把活动的code。

 进口android.app.FragmentTransaction;
进口android.os.Bundle;
进口android.support.v4.app.Fragment;进口com.google.android.gms.maps.CameraUpdate;
进口com.google.android.gms.maps.CameraUpdateFactory;
进口com.google.android.gms.maps.GoogleMap;
进口com.google.android.gms.maps.SupportMapFragment;
进口com.google.android.gms.maps.model.CameraPosition;
进口com.google.android.gms.maps.model.LatLng;
进口com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity;公共类ActivityPrincipal扩展SlidingActivity {    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_activity_principal);        使用GoogleMap地图=((SupportMapFragment)getSupportFragmentManager()findFragmentById(R.id.fragMapa)。)的GetMap();        经纬度coordenadasGT =新的经纬度(15.45368,-90.485115);
        CameraPosition坎波斯=新CameraPosition.Builder()
        .TARGET(coordenadasGT)
        .zoom(8)
        。建立();        的CameraUpdate camUpd = CameraUpdateFactory.newCameraPosition(坎波斯);        mapa.moveCamera(camUpd);
    }    / *
    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.activity_principal,菜单);
        返回true;
    }
    * /}


解决方案

我设法整合谷歌地图v2和jfeinstein10的SliderMenu。
我的动态扩展ActionBarActivity和我使用滑块菜单以编程方式构建的:

 公共无效的onCreate(捆绑savedInstanceState){
            super.onCreate(savedInstanceState);            的setContentView(R.layout.main);            SlidingMenu菜单=新SlidingMenu(本);
            menu.setMode(SlidingMenu.LEFT_OF);
            menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
            menu.setFadeDegree(0.35f);
            menu.attachToActivity(这一点,SlidingMenu.SLIDING_WINDOW);
            menu.setMenu(R.layout.options);
            menu.setShadowDrawable(R.drawable.shadow);
            menu.setShadowWidthRes(R.dimen.shadow_width);
            menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
            menu.setFadeDegree(0.35f);
            menu.setOnOpenedListener(本);            FragmentManager fmanager = getSupportFragmentManager();
            片段片段= fmanager.findFragmentById(R.id.mapView);
            SupportMapFragment supportmapfragment =(SupportMapFragment)片段;            MMAP = supportmapfragment.getMap();
            mMap.getUiSettings()setZoomControlsEnabled(假)。
            mMap.setOnMapClickListener(本);
            mMap.setOnInfoWindowClickListener(本);
            mMap.setOnMarkerClickListener(本);
            mMap.setMyLocationEnabled(真);
            mMap.setOnMyLocationChangeListener(本);
            mMap.setOnMyLocationButtonClickListener(本);
    }

MapView的是在我的布局片段:

 <片段
            机器人:ID =@ + ID /图形页面
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            类=com.google.android.gms.maps.SupportMapFragment/>

I want to implement Google maps v2 and SliderMenu of jfeinstein10, I managed to implement the SliderMenu but when I want to add the map in the activity, I get error

GoogleMap map = ((SupportMapFragment) getSupportFragmentManager (). FindFragmentById (R.id.fragMapa)). GetMap ();

being more specific in getSupportFragmentManager ()

any solution for that integrate both. I put the code of the activity.

import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.Fragment;

import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity;

public class ActivityPrincipal extends SlidingActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activity_principal);

        GoogleMap mapa = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.fragMapa)).getMap();

        LatLng coordenadasGT = new LatLng(15.45368,-90.485115);
        CameraPosition camPos = new CameraPosition.Builder()
        .target(coordenadasGT)
        .zoom(8)
        .build();

        CameraUpdate camUpd = CameraUpdateFactory.newCameraPosition(camPos);

        mapa.moveCamera(camUpd);
    }

    /*
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_principal, menu);
        return true;
    }
    */

}
解决方案

I managed to integrate Google maps v2 and SliderMenu of jfeinstein10.My Activity extends ActionBarActivity and i am using slider menu by constructing it programmatically :

    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

            SlidingMenu menu = new SlidingMenu(this);
            menu.setMode(SlidingMenu.LEFT_OF);
            menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
            menu.setFadeDegree(0.35f);
            menu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
            menu.setMenu(R.layout.options);
            menu.setShadowDrawable(R.drawable.shadow);
            menu.setShadowWidthRes(R.dimen.shadow_width);
            menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
            menu.setFadeDegree(0.35f);
            menu.setOnOpenedListener(this);

            FragmentManager fmanager = getSupportFragmentManager();
            Fragment fragment = fmanager.findFragmentById(R.id.mapView);
            SupportMapFragment supportmapfragment = (SupportMapFragment) fragment;

            mMap = supportmapfragment.getMap();
            mMap.getUiSettings().setZoomControlsEnabled(false);
            mMap.setOnMapClickListener(this);
            mMap.setOnInfoWindowClickListener(this);
            mMap.setOnMarkerClickListener(this);
            mMap.setMyLocationEnabled(true);
            mMap.setOnMyLocationChangeListener(this);
            mMap.setOnMyLocationButtonClickListener(this);
    }

mapView is a Fragment in my layout:

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

这篇关于谷歌地图整合和SlidingMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:39