2012-04-20 51 views
-1

我開發地圖應用程序,我在其中顯示Google地圖和覆蓋項目。現在我想要自定義對話框的覆蓋項目的水龍頭,所以你可以告訴我,任何類,我可以輕鬆實現?客戶對話點擊itemizeoverlay

感謝 聶

回答

1
在這樣

@Override 
    protected boolean onTap(int index) 
    { 
     item = mOverlays.get(index); 
     displaySearchResultBubble(); 


     return true; 
    } 

和方法的過度類別的呼叫ONTAP馬託

private void displaySearchResultBubble() { 


     //Hide the bubble if it's already showing for another result 
     mapView.removeView(bubble); 
     bubble.setVisibility(View.GONE); 



     /// 
     GeoPoint point11 = item.getPoint(); 
     /// 
     //Set some view content 

     venueName.setText("Your Message"); 
     MapView.LayoutParams params = new MapView.LayoutParams(
      LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 
      point11, MapView.LayoutParams.BOTTOM_CENTER); 

     bubble.setLayoutParams(params); 

     mapView.addView(bubble); 

     mapView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); 
     Runnable r = new Runnable() { 
      public void run() { 
       Animation fadeIn = AnimationUtils.loadAnimation(mContext, R.anim.fadein); 
       bubble.setVisibility(View.VISIBLE); 
       bubble.startAnimation(fadeIn); 
      } 
     }; 

     //This projection and offset finds us a new GeoPoint slightly below the actual OverlayItem, 
     //which means the bubble will end up being centered nicely when we tap on an Item. 
     Projection projection = mapView.getProjection(); 
     Point p = new Point(); 

     projection.toPixels(point11, p); 
     p.offset(0, -(bubble.getMeasuredHeight()/2)); 
     GeoPoint target = projection.fromPixels(p.x, p.y); 

     //Move the MapView to our point, and then call the Runnable that fades in the bubble. 
     mapView.getController().animateTo(target, r); 
    } 

和你泡

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center" 
    android:paddingLeft="62dip" 

    > 
    <LinearLayout 

    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 

    > 
    <TextView 
    android:layout_width="185dip" 
    android:layout_height="wrap_content" 
    android:id="@+id/venuename" 
    android:gravity="center_vertical" 
    android:singleLine="true" 
    android:hint="Hello" 
    android:textSize="26px" 
    > 
    </TextView> 
</LinearLayout> 
</RelativeLayout> 

在上添加此創建方法

LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); 
bubble = (RelativeLayout) inflater.inflate(R.layout.bubble, mapView, false); 
venueName = (TextView) bubble.findViewById(R.id.venuename); 

希望你有你的答案是完整的解決方案