0

注:MapView内のメソッドを上書きする必要があるため、MapFragmentは使用しません。

MapViewを表示するために次のコードを使用します。

mapView = (MapView) view.findViewById(R.id.map);
mapView.onCreate(null);
mapView.onResume();

このxmlを使用すると:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

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

    ...

</RelativeLayout>

これはうまくいきます。しかし、プロジェクトをjar(クローズドソース)としてエクスポートする必要があるため、xmlレイアウトを使用できなくなりました。

私のレイアウトは非常に単純なので、コードで手動で作成できます。だから今私はこれを使用しています:

mapView = new MapView(context);
mapView.setLayoutParams(
    new LayoutParams(
        LayoutParams.MATCH_PARENT, 
        LayoutParams.MATCH_PARENT
    )
);
view.addView(mapView);
mapView.onCreate(null);

しかし、onCreateステートメントでNullPointerExceptionが発生します。

私は何が間違っているのですか?

4

1 に答える 1

0
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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=".GeoPosActivity"
android:orientation="vertical" >

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myLocationText"
    android:layout_width="match_parent"
    android:layout_height="match_parent"       
    android:orientation="vertical"
    android:text="TEST"
    android:layout_weight="50"
    />

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/myMapView"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:enabled="true"
    android:clickable="true"
    android:layout_weight="50"/>

</LinearLayout>

これは私のアプリです。そしてそれは機能します、

なぜ「.jar」を使用するのですか? アプリケーションをテストするには、Android を搭載したデバイスを使用するのが最適です。

于 2013-03-14T14:10:21.543 に答える