|
我这样试了一下 拖动的时候是网络上的图片
- public void runTest() {
- log("替换infoWindow adapter测试");
- aMap.setInfoWindowAdapter(this);
- marker = aMap.addMarker(new MarkerOptions().position(Constants.BEIJING).title("test").snippet("this is a test"));
- marker.showInfoWindow();
- }
-
- @Override
- public View getInfoWindow(Marker marker) {
- View infoContent = LayoutInflater.from(context).inflate(
- R.layout.custom_info_contents, null);
- render(marker, infoContent);
- return infoContent;
- }
- @Override
- public View getInfoContents(Marker marker) {
- View infoContent = LayoutInflater.from(context).inflate(
- R.layout.custom_info_contents, null);
- render(marker, infoContent);
- return infoContent;
- }
- ImageView imageView;
- /**
- * 自定义infowinfow窗口
- */
- public void render(Marker marker, View view) {
- imageView = (ImageView) view.findViewById(R.id.badge);
- imageView.setImageResource(R.drawable.badge_wa);
- //开启网络下载任务
- new MyTask().execute("");
- String title = marker.getTitle();
- TextView titleUi = ((TextView) view.findViewById(R.id.title));
- if (title != null) {
- SpannableString titleText = new SpannableString(title);
- titleText.setSpan(new ForegroundColorSpan(Color.RED), 0,
- titleText.length(), 0);
- titleUi.setTextSize(15);
- titleUi.setText(titleText);
- } else {
- titleUi.setText("");
- }
- String snippet = marker.getSnippet();
- TextView snippetUi = ((TextView) view.findViewById(R.id.snippet));
- if (snippet != null) {
- SpannableString snippetText = new SpannableString(snippet);
- snippetText.setSpan(new ForegroundColorSpan(Color.GREEN), 0,
- snippetText.length(), 0);
- snippetUi.setTextSize(20);
- snippetUi.setText(snippetText);
- } else {
- snippetUi.setText("");
- }
- }
- Handler handler = new Handler();
- /**
- * 又网络下载操作,使用异步任务
- */
- class MyTask extends AsyncTask<String , String, String> {
- public MyTask() {
- }
- @Override
- protected String doInBackground(String... arg0) {
- loadImage();
- return null;
- }
- @Override
- protected void onCancelled() {
- // TODO Auto-generated method stub
- super.onCancelled();
- }
- @Override
- protected void onPostExecute(String result) {
- // TODO Auto-generated method stub
- super.onPostExecute(result);
- }
- public boolean loadImage() {
- try {
- URL url = new URL("http://lbsbbs.amap.com/template/LBS_1/imgs/a_logo.png"); //path图片的网络地址
- HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
- if(httpURLConnection.getResponseCode() == HttpURLConnection.HTTP_OK){
- final Bitmap bitmap = BitmapFactory.decodeStream(httpURLConnection.getInputStream());
- // ImageView testview = new ImageView(context);
- //
- // imageView.setImageBitmap(bitmap);//加载到ImageView上
- // System.out.println("加载网络图片完成");
- //
- // BitmapDescriptor descriptor = BitmapDescriptorFactory.fromView(testview);
- // mMarker.setIcon(descriptor);
- handler.post(new Runnable() {
- @Override
- public void run() {
- imageView.setImageBitmap(bitmap);//加载到ImageView上
- }
- });
- return true;
- }else{
- System.out.println("加载网络图片失败");
- return false;
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return false;
- }
- }
复制代码 |
|