3

タブにマップビューが必要です。添付の例は、インテントを使用する場合にこれを行う方法を示しています。次に、マップビューのズームレベルを変更したいと思います。インテントを使用していますが(または完全に異なる解決策があります)、どうすればこれを行うことができますか?

アクティビティコード:

public class TabMapsExample extends TabActivity {    
    TabHost mTabHost;        
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);  
        Context ctx = this.getApplicationContext();         
        //tab 1
        mTabHost = getTabHost();
        TabSpec tabSpec1 = mTabHost.newTabSpec("tab_test1");
        tabSpec1.setIndicator("Map1");
        Intent i1 = new Intent(ctx, MapTabView.class);
        tabSpec1.setContent(i1);
        mTabHost.addTab(tabSpec1);          
        //tab2
        mTabHost = getTabHost();
        TabSpec tabSpec2 = mTabHost.newTabSpec("tab_test1");
        tabSpec2.setIndicator("Map2");
        Intent i2 = new Intent(ctx, MapTabView.class);
        tabSpec2.setContent(i2);
        mTabHost.addTab(tabSpec2);          
        //tab 3
        mTabHost = getTabHost();
        TabSpec tabSpec3 = mTabHost.newTabSpec("tab_test1");
        tabSpec3.setIndicator("Map");
        Intent i3 = new Intent(ctx, MapTabView.class);
        tabSpec3.setContent(i3);
        mTabHost.addTab(tabSpec3);    
    }
}

レイアウトコード:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/maptablayout" android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="fill_parent" android:layout_width="fill_parent"
        android:background="#000000" android:orientation="vertical">
        <TextView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent" android:layout_height="50px"
            android:id="@+id/textview" />
        <com.google.android.maps.MapView
            android:id="@+id/mapview" android:layout_width="fill_parent"
            android:layout_height="fill_parent" android:clickable="true"
            android:apiKey="" />
    </LinearLayout>
</RelativeLayout>

どうも

4

3 に答える 3

1

ズームは、MapViewのズームコントロールをアクティブにしてユーザーにズームインまたはズームアウトさせるか、代わりにプログラムを使用して行うことで可能になります。

mapView.getController().zoomIn();

また

mapView.getController().zoomOut();

また

mapView.getController().setZoom(...);

または、外部からインテントの追加データを渡すこともできます。今推測しているだけですが、基本的には次のようなことができます

Intent intent = new Intent(this, MyMapActivity.class); //this is just one way of specifying it
intent.putExtra(MyMapActivity.ZOOM_LEVEL_CONSTANT, 10);
startActivity(intent);

MyMapActivityのonCreate(...)内で、渡されたデータを次のように読み取ることができます。

Bundle retrievedData = this.getIntent().getExtras();
if (retrievedData != null) {
   int zoomLevel = retrievedData.getInt(ZOOM_LEVEL_CONSTANT);
   mapView.getController.setZoom(zoomLevel);
}

編集: タブコンテンツを動的に入力するには:

TabSpec tabSpec = tabHost.newTabSpec("Android X");
tabSpec.setContent(new TabContentFactory() { 
   public View createTabContent(String arg0) { 
       //return the view to add as content
       return theView; 
   }
});
于 2010-01-08T11:50:59.453 に答える
1

MapControllerを使用してみてください:

    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setBuiltInZoomControls(true);
    MapController mapController = mapView.getController();
    mapController.setZoom(10);

AndroidでのGoogleマップの使用も参照してください

更新
同じレイアウトの複数のインスタンスを作成しましたが、必要なMapViewのインスタンスをIDで取得する際に問題が発生します。タブごとに別々のレイアウトを使用できますか?またはそれらを動的に作成しますか?

于 2010-01-08T11:51:39.170 に答える
1

@ juri: インテントは onCreate() の外でもデータを受け取ることができますか? (たとえば、インテントの作成時だけでなく、実行時にズームレベルを動的に設定するため)

于 2010-01-08T16:46:22.703 に答える