2012-09-06 86 views
0

我有一個選項卡選項卡,並且在單擊此選項卡時,我想將內容設置爲OSM Map(其setContent())。我這樣做:如何顯示osm地圖

View bottomMap = createBottomTabView(bottomTabHost.getContext(), "Map", R.drawable.map); 
bottomTabHost.addTab(bottomTabHost.newTabSpec("Map").setIndicator(bottomMap).setContent(new Intent(this, OSMMapClass.class))); 

public class MapBottomTab extends MapActivity 
{ 
     @Override 
     public void onCreate(Bundle savedInstanceState) 
     { 
     super.onCreate(savedInstanceState); 
     org.osmdroid.views.MapView mapView = new org.osmdroid.views.MapView(this, 256); 
     setContentView(mapView); 
     } 
} 

應該加載Map的變化......?

回答

0

你只需要定義的XML地圖佈局中的LinearLayout例如像這樣

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:id="@+id/mapLayoutFinal" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <!-- you do your map layout (<org.osmdroid.views.MapView ... />) --> 

    </LinearLayout> 

,然後你在活動上宣佈此佈局創建方法是這樣的:

super.onCreate(savedInstanceState); 
    setContentView(R.layout.main_fragment); 
LinearLayout rl = (LinearLayout) findViewById(R.id.mapLayoutFinal); 
    this.mOsmv.setLayoutParams(new LinearLayout.LayoutParams(
      LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 
    rl.addView(mOsmv); 

這應該工作。 PS:我使用的是osmdroid,我只是在活動中定義了所有內容,只有線性佈局,我在那裏粘貼了我的視圖。