2012-04-15 81 views
1

我有一堆用默認標記的自定義項目。android google map onTap

我加載所有標記之後,我正在使用服務更新其可繪製照片。 新的照片是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; 

} 

一兩件事,當我使用地圖的第一加載時,dummie標記是在一個點。 當它改變的標記,該標記移動有點...我不知道爲什麼..

編輯:找到一個解決方案感謝答案波紋管:

我的新方法的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; 

} 

回答

0

我猜你需要在爲ImageView設置Drawable時再次創建Drawable - 否則ImageView和標記共享drawable,並且當ImageView放置時都會調整大小。

+0

您的意思是像 \t \t Drawable profile = item.getMarker(0); \t \t profilePicture.setImageDrawable(profile); – 2012-04-15 22:40:14

+0

ohhh得到它..解決了謝謝! – 2012-04-15 22:43:39

+0

你能否請評論工作線?有人可能會在將來使用它... – 2012-04-15 22:46:31