【问题标题】:android google map onTapandroid 谷歌地图 onTap
【发布时间】:2012-04-16 06:44:58
【问题描述】:

我有一堆带有默认标记的自定义项目。

在我加载所有标记后,我正在使用一项服务来更新他们的可绘制照片。 新照片是 50 X 50。

一切都很好,直到我点击一个标记并且我的 onTap 警报框被激活。 然后我的标记恢复到标记新照片的原始(小)尺寸。

这是我的物品:

                Bitmap bitmap = ((BitmapDrawable) picture).getBitmap();
                picture = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 50, 50, true));
                picture.setBounds(0, 0, 50,50);
                marker.getItem(0).setMarker(picture);
                mapView.invalidate(); 

这是我的 onTap:

   protected boolean onTap(int index) {
   OverlayItem item = mapOverlays.get(index);
   Dialog dialog = new Dialog(context);
   dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
   dialog.setContentView(R.layout.map_menu);
   dialog.setCanceledOnTouchOutside(true);
   TextView userName = (TextView)dialog.findViewById(R.id.map_menu_name);
   ImageView profilepicture = (ImageView)dialog.findViewById(R.id.map_menu_profile_picture);
   if (item.getMarker(0) == null)
       profilepicture.setImageDrawable(defaultMarker);
   else
       profilepicture.setImageDrawable(item.getMarker(0));

   userName.setText(item.getTitle());
   //dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
   dialog.show();

  return true;

}

还有一件事,当我使用第一次加载地图时,虚拟标记位于某个点。 当它改变标记时,标记会移动一点......我不知道为什么......

编辑:由于下面的答案找到了解决方案:

我的新 onTap 方法:

   @Override
  protected boolean onTap(int index) {
   OverlayItem item = mapOverlays.get(index);
   Dialog dialog = new Dialog(context);
   dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
   dialog.setContentView(R.layout.map_menu);
   dialog.setCanceledOnTouchOutside(true);
   TextView userName = (TextView)dialog.findViewById(R.id.map_menu_name);
   ImageView profilePicture = (ImageView)dialog.findViewById(R.id.map_menu_profile_picture);
   if (item.getMarker(0) == null)
     profilePicture.setImageDrawable(defaultMarker);
   else
   {
       Bitmap bitmap = ((BitmapDrawable) item.getMarker(0)).getBitmap();
       Drawable profile = new BitmapDrawable(Bitmap.createScaledBitmap(bitmap, 50, 50, true));
       profilePicture.setImageDrawable(profile);
   }

   userName.setText(item.getTitle());
   //dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
   dialog.show();

  return true;

}

【问题讨论】:

    标签: android google-maps-api-3 itemizedoverlay


    【解决方案1】:

    我猜你需要在为 ImageView 设置 Drawable 时再次创建 Drawable - 否则 ImageView 和标记共享 drawable 并且当 ImageView 布局时都会调整大小。

    【讨论】:

    • 你的意思是像 Drawable profile = item.getMarker(0); profilePicture.setImageDrawable(profile);
    • 请您对有效的行发表评论吗?将来有人可能会使用它...
    • 我已经编辑了我的原始帖子并在最后添加了有效的 noTap 方法。一般来说,我刚刚创建了一个新的 Drawable 对象并在警报对话框图像视图中使用它而不是使用相同的地图中的对象
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    • 2012-11-27
    • 2015-12-19
    • 2015-12-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多