2012-12-04 52 views
0

我有一個疊加圖層,其中包含許多可供選擇和拖動的可繪製圖層。鎖定MapView移動

問題是,當一個對象被拖動時,MapView也會移動。

有沒有辦法可以鎖定MapView?

我一直在使用map.setClickable(false)

我也用嘗試:

 map.setOnTouchListener(new OnTouchListener() { 

      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       if(event.getAction() == MotionEvent.ACTION_MOVE) { 
        return true; 
       } 
       return false; 
      } 
     }); 

兩個嘗試不鎖運動但禁止選擇覆蓋的能力。

任何想法?

感謝

+0

可能是值得考慮看看到[新地圖API(V2)(https://developers.google.com/maps/documentation/android/marker),作爲標記被設計成互動用一個'draggable'標記來表示用戶是否可以改變標記的位置:*「將標記的'draggable'屬性設置爲'true'允許用戶改變標記」*「的位置。 –

回答

0

在我的老項目中,我設置MapView.clickable(false),並添加了佈局是MapView。不知道這是最好的解決方案。

UPDATE:

<RelativeLayout 
      a:id="@+id/map_block" 
      a:layout_width="fill_parent" 
      a:layout_height="wrap_content" 
      > 
      <RelativeLayout 
       a:id="@+id/map_holder" 
       a:layout_width="fill_parent" 
       a:layout_height="150dp" 
       /> 

     <!-- Layout for catching clicks --> 
      <TextView 
       a:id="@+id/map_click_receiver" 
       a:layout_width="fill_parent" 
       a:layout_height="150dp" 
       /> 
</RelativeLayout> 

map_holder編程添加MapView

mMapView = new MapView(mContext, getString(R.string.gmaps_key)); 
mapHolder.addView(mMapView, new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); 

哦,是和(但我認爲mMapClickReceiver.setClickable(false)還可以幫助):

mMapClickReceiver.setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         // something to do 
        } 
       }); 
+0

你是如何在你的mapview上添加布局的? – sam

+0

@sam,我更新答案。 – nfirex

0

該作品對我來說:

map.setOnTouchListener(new OnTouchListener(){ 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     if(event.getAction() == MotionEvent.ACTION_MOVE) { 
      return true; 
     } 
     return v.onTouchEvent(event); 
    } 

}); 
+0

基本上不叫super.OnTouch吧? – taxeeta

+0

基本上不是'return false'讓視圖處理事件 –