-1

我正在开发地图应用程序,其中我有显示谷歌地图和覆盖项目。现在我想要自定义对话框点击覆盖项目,所以你能告诉我有没有我可以轻松实现的类?

谢谢尼克

4

2 回答 2

1

检查以下演示:

http://eagle.phys.utk.edu/guidry/android/mapOverlayDemo.html

于 2012-04-20T11:56:45.573 回答
1

在你的过度类调用的 ontap 方法中,像这样

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


        return true;
    }

方法是

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>

将此添加到您的 on create 方法中

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

希望你得到你的答案这是完整的解决方案

于 2012-04-20T12:07:15.650 回答