我想在scrollView中使用MapView。这样做会导致地图出现滚动问题,并且当您想要滚动地图时,整个页面将滚动。我在这里发现了这个问题的解决方案:MapView inside a ScrollView?
我创建了一个名为myMapView的类。这里是它的代码:
覆盖MapView中的onTouchEvent
package com.wikitude.example;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.google.android.maps.MapView;
public class myMapView extends MapView {
public myMapView(Context context, String apiKey) {
super(context, apiKey);
// TODO Auto-generated constructor stub
}
public myMapView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public myMapView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
this.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
// Handle MapView's touch events.
super.onTouchEvent(ev);
return false;
}
}
,但是当我尝试使用它在我的MapActivity这样的:
myMapView myview = (myMapView) findViewById(R.id.themap);
它抛出这个错误:Undable to start activity ComponentInfo{com.smtabatabaie.example/com.smtabatabaie.mainActivity}: java.lang.ClassCastException: com.google.android.maps.MapView
。
我没有找到问题所在,看起来一切正常。我会不胜感激,如果有人可以帮我这个
谢谢
它是什么错误投掷,请张贴您的问题的Logcat错误日志。 –
感谢Vishwa,我编辑了我的问题并发布了错误 – m0j1