標籤:android style blog class code java tar javascript ext width color
把一個人一個月的軌跡曆史描繪出來,並實現按時間順序回放。小弟菜鳥一枚,代碼品質不高,高手勿噴,謝謝。
關於描點和描線,百度地圖都有自己的API,大家都應該會了;至於播放動畫,肯定不止一種方法,如果大家有好的方法,分享出來,小弟感激不盡。
我的方法是:在一個線程裡,開始播放後,遍曆存放item的list,找到當前的item,移除他的marker,然後給他換一個marker,再添加到list裡面,然後睡眠;接著就判斷,如果不是當前item,該什麼樣子就什麼樣子,如此迭代就可以了。
代碼如下:
/** 軌跡回放邏輯處理 **/private Runnable rz = new Runnable(){ @Override public synchronized void run() { while (isStartRun) { for (int i = index; i < mGeoList.size(); i++) { OverlayItem item = mGeoList.get(i); flag = index; sendMsg(MapApplication.LOCATEOVER_NOTICE_ADAPTER); mOverlayGraphic.removeItem(item); item.setMarker(res.get(3)); if (!isBcak) { break; } mOverlayGraphic.addItem(item); mMapView.refresh(); SystemUtils.sleep(1000); mOverlayGraphic.removeItem(item); if (index == 0) { item.setMarker(res.get(1)); } else if (index == mGeoList.size() - 1) { item.setMarker(res.get(2)); isStartRun = false; isFinish = false; } else { View view = mInflater.inflate(R.layout.overlay_item, null); TextView userItemTv1 = (TextView) view.findViewById(R.id.item_tv1); userItemTv1.setText(index + 1 + ""); Bitmap bmp = userLocateUtil.createNewBitmap(view); Drawable drawable = new BitmapDrawable(bmp); item.setMarker(drawable); } if (!isBcak) { break; } mOverlayGraphic.addItem(item); mMapView.refresh(); index++; if (!isFinish) { index = 0; sendMsg(MapApplication.LOCATEOVER_PLAY_FINISH); break; } } } }}; private Handler handler = new Handler(){ public void handleMessage(Message msg) { switch (msg.what) { case MapApplication.LOCATEOVER_CHANGE_MAPVIEW: changeMapView(); break; case MapApplication.LOCATE_MAPVIEW_REFRESH: mMapView.refresh(); mMapView.getController().zoomToSpan(mOverlayGraphic.getLatSpanE6(), mOverlayGraphic.getLonSpanE6()); mMapView.getController().setCenter(mOverlayGraphic.getCenter()); PocProgressDialog.cancel(); break; case MapApplication.LOCATEOVER_PLAY_FINISH: Toast.makeText(MainActivity.mainActivity, "播放完畢", Toast.LENGTH_SHORT).show(); flag = 99999; adapter.notifyDataSetChanged(); play.setText("開始回放"); break; case MapApplication.LOCATEOVER_NOTICE_ADAPTER: adapter.notifyDataSetChanged(); // mListView.setSelection(flag);備用 break; } }};
主要的邏輯就在這裡了,下面看看效果:
播放前:
播放時:
左邊對應的listview: