我想在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