2013-02-27 71 views
0

我想使用onTouch事件(處理地圖上對象的旋轉手勢)。我無法在mainActivity中擴展Activity並使用片段。所以我想我應該使用MapView類。我怎樣才能在谷歌地圖android(V2)的新版本中做到這一點? 這不會顯示任何內容。只有手機上的空白屏幕。如何在谷歌地圖V2 android中使用MapView?

在MainActivity:

public class MainActivity extends Activity { 

// MapView mapV; 
// GoogleMap map; 



@Override 
    protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    mapV = ((MapView) findViewById(R.id.map)); 
    map = mapV.getMap(); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
    getMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
    } 

} 

的activity_main.xml中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".MainActivity" > 

    <com.google.android.gms.maps.MapView 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

</RelativeLayout> 
+0

爲什麼不使用MapFragment?你在使用MapFragment時遇到什麼問題? – 2013-02-28 09:34:43

+0

我想要做的就是能夠在地圖上旋轉對象(標記)。我想也許通過使用mapview我可以訪問ontouch事件,這是視圖類..不知道可能是我錯了。但我不知道如何解決這個問題 – 2013-02-28 09:49:57

+0

你是什麼意思通過旋轉?還有針對MapFragment的tap/touch監聽器。 – 2013-02-28 09:57:51

回答

0

在你的活動中,你必須實現所有的生命週期方法(在onPause等),並在那裏將其轉發到你的地圖,例如

@Override 
public void onPause() { 
    map.onPause(); 
    super.onPause(); 
}