2011-12-05 32 views
3

我已經啓用內置的縮放控件在我的谷歌地圖應用程序,但是,它顯示了我的頁腳按鈕面板上:Google Maps API上的ZoomControls - 如何將它移動到ButtonBar上方?

enter image description here

我想縮放控件是頁腳按鈕欄的一個頂部。

public class MinuteMapActivity extends MapActivity { 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    // the methods on the map are initialised here - onCreate 
    zoomControls(); 
    satelliteDisplay(); 
    snapToMap(); 

} 

// method for Zoomcontrols 
private void zoomControls() { 
    LinearLayout zoomControls = (LinearLayout) findViewById(R.id.zoomControls); 
    MapView zoomLayout = (MapView) findViewById(R.id.MapView); 
    //zoomControls.addView(zoomLayout, new  LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
    zoomLayout.setBuiltInZoomControls(true); 
} 

XML佈局:

?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<com.google.android.maps.MapView 
    android:id="@+id/MapView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:enabled="true" 
    android:clickable="true" 
    android:apiKey="0zZsLcQS5Zeiqjbo1n8-nn2CqtxKIuTq2T6bskg" 
    /> 

<!-- set zoom controls on map at the bottom --> 
<LinearLayout 
    android:id="@+id/zoomControls" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    /> 

如果我能

//zoomControls.addView(zoomLayout, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

崩潰。

有關如何將縮放控件移動到底部欄上的一些幫助。

回答

1

我認爲它崩潰的原因是因爲您試圖將LinearLayout參數分配給RelativeLayout中的佈局,所以您將不得不使用RelativeLayout.LayoutParams代替。

此外,我對你爲什麼使用LinearLayout作爲縮放控件而不是預定義視圖ZoomControls感到有點困惑。也許它會爲你節省一點時間?

如果你想放置你上面的底視圖縮放控件使用

<ZoomControls 
    android:id="@+id/zoomControls" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_above="@+id/buttonbar" /> 

假設你打電話給你的按鈕欄視圖buttonbar

+0

啊,我當時並不知道有一個預定義的視圖叫ZoomControls。讓我試試看,我會回到你身邊。 – Zukky

+0

完美地工作,謝謝。 – Zukky

0

可能你已經錯過了兩行代碼在你

  <com.google.android.maps.MapView. 

所以它這兩條線粘貼,你就會得到它。其工作100%。

   android:enabled="true" 
       android:clickable="true" 
相關問題