2011-01-12 68 views
3

我正在尝试创建MapView的扩展版本。Android Custom MapView

问题是当定义了扩展版本MapView时,mapview不能平移。

我正在执行onTouchListener在我的自定义地图视图中。

我也想知道是否有任何方法可以从我可以平移mapview。

使用相同的源代码使用股票版本的MapView时,问题不会持续存在。

编辑

MyMapView来源:

public class MyMapView extends MapView{ 

    public MyMapView(Context context, String apiKey) { 
     super(context, apiKey); 

    } 
    public MyMapView(Context context, AttributeSet attrs) { 
     super(context, attrs); 

    } 
    public MyMapView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 

    } 

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     if(event.getAction()==MotionEvent.ACTION_DOWN){ 
      Log.v("MyMapView","Touched"); 
     } 

     return false ; 
    } 



} 

onCreate()MapActivity

protected void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.mapper); 
    mMapView=(MyMapView) findViewById(R.id.mapper_map); 
    mMapView.setSatellite(false);  

} 
+0

我怀疑这可能是因为你从一些onTouch方法返回true - 尝试返回false;这应该允许你的类做一些事情,然后让触摸事件传播到基类来做它的东西。但让我们看看你的代码。 – 2011-01-12 12:54:23

+0

@ John J Smith,代码在帖子中更新。 – Shardul 2011-01-13 06:55:43

回答

0

我错了。

mMapView=(MyMapView) findViewById(R.id.mapper_map); 

应该

mMapView=(MapView) findViewById(R.id.mapper_map); 

这解决了问题。

Thankx反正。

1

你的onTouchEvent()应该返回false,否则会消耗事件。

您还可以实例化MapController并使用它来更改视图。以下是我正在处理的应用中的代码段:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.mapview); 

    myMapView = (MapView) findViewById(R.id.myMapView); 
    myMapView.setBuiltInZoomControls(true); 
    myMapController = myMapView.getController(); 

    myPoint = new GeoPoint(0, 0); 
    myMapController.setCenter(myPoint); 
    myMapController.zoomToSpan(360 * MILLION, 360 * MILLION); 
}