Android的图形页面:animateTo行不通的,而地图平移 [英] Android MapView: animateTo doesnt work while map is panning
问题描述
在code以下执行以下操作:
当检查焦点复选框,地图动画在地图上叠加一个项目。
还有一个问题:
当我拖动地图,这样,当我选中该复选框地图还在动,检查没有任何视觉效果。
任何想法?
列表<&叠加GT; mapOverlays;
可绘制可绘制;
AssetMarkersOverlay itemizedOverlay;
私人复选框autofocusCheckBox;
MapView类MapView类;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 的setContentView(R.layout.main); 图形页面=(图形页面)findViewById(R.id.mapview);
mapView.getController()setZoom(4)。
mapView.setBuiltInZoomControls(真); mapOverlays =调用MapView.getOverlays();
绘制= this.getResources()getDrawable(R.drawable.bubble_blue)。
itemizedOverlay =新AssetMarkersOverlay(绘制); 字符串ASSETNAME =TEST;
INT纬度= 3;
INT LON = 3; ArrayList的<&GeoPoint的GT; geoPointList =新的ArrayList<&GeoPoint的GT;(); 的GeoPoint点=新的GeoPoint(纬度,经度); autofocusCheckBox =(复选框)findViewById(R.id.showInMap);
autofocusCheckBox.setTag(点);
autofocusCheckBox
.setOnCheckedChangeListener(新OnCheckedChangeListener(){ 公共无效onCheckedChanged(CompoundButton buttonView,
布尔器isChecked){
如果(&器isChecked功放;&安培; buttonView.getTag()!= NULL){
focusAsset((的GeoPoint)buttonView.getTag());
}
}
}); geoPointList.add(点);
itemizedOverlay.addOverlay(纬度,经度,ASSETNAME,ASSETNAME); mapOverlays =调用MapView.getOverlays();
mapOverlays.clear();
mapView.postInvalidate();
mapOverlays.add(itemizedOverlay);
fitPoints(geoPointList,MapView类);
mapView.postInvalidate();}私人无效focusAsset(GeoPoint的点){
mapView.requestFocus();
mapView.clearAnimation();
。mapView.getController()stopAnimation(真);
mapView.getController()setZoom(14)。
。mapView.getController()animateTo(点);
mapView.postInvalidate();
}
我用了一个AsyncTask的解决类似的问题。它的工作原理,但有时并非所有的时间。基本上,我只是叫animateTo几次有一些延误。值得一提的似乎getMapCenter返回时,可以向动画,而不是目前的真正中心,我想用这个来检测,如果它到了新的位置,但还是不它的位置和不工作了很多时间。此外,它似乎没有动画至少会持续更长的时间超过1000毫秒ICS如此大的潜在等待那么长时间拨打电话可以解决您的问题了。
The code below does the following: When checking the "focus" checkbox, the map animates to the single overlay item in the map. There is one problem: When i drag the map so that the map is still moving when I check the checkbox, the checking has no visual effect. Any ideas?
List<Overlay> mapOverlays;
Drawable drawable;
AssetMarkersOverlay itemizedOverlay;
private CheckBox autofocusCheckBox;
MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.getController().setZoom(4);
mapView.setBuiltInZoomControls(true);
mapOverlays = mapView.getOverlays();
drawable = this.getResources().getDrawable(R.drawable.bubble_blue);
itemizedOverlay = new AssetMarkersOverlay(drawable);
String assetName = "TEST";
int lat = 3;
int lon = 3;
ArrayList<GeoPoint> geoPointList = new ArrayList<GeoPoint>();
GeoPoint point = new GeoPoint(lat, lon);
autofocusCheckBox = (CheckBox) findViewById(R.id.showInMap);
autofocusCheckBox.setTag(point);
autofocusCheckBox
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if (isChecked && buttonView.getTag() != null) {
focusAsset((GeoPoint) buttonView.getTag());
}
}
});
geoPointList.add(point);
itemizedOverlay.addOverlay(lat, lon, assetName, assetName);
mapOverlays = mapView.getOverlays();
mapOverlays.clear();
mapView.postInvalidate();
mapOverlays.add(itemizedOverlay);
fitPoints(geoPointList, mapView);
mapView.postInvalidate();
}
private void focusAsset(GeoPoint point) {
mapView.requestFocus();
mapView.clearAnimation();
mapView.getController().stopAnimation(true);
mapView.getController().setZoom(14);
mapView.getController().animateTo(point);
mapView.postInvalidate();
}
I used an AsyncTask to fix a similar issue. It works sometimes but not all the time. Basically I just call animateTo a few times with some delays. Worth noting it appears getMapCenter returns the location it is animating to rather than the current true center as I tried using this to detect if it got to the new location yet or not and it doesn't work a lot of the time. Also it appears no animation will last longer than 1000 milliseconds at least on ICS so potentially waiting that long before making a call could fix your issue.
这篇关于Android的图形页面:animateTo行不通的,而地图平移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!