0

当我单击 dispatchTap() 方法时,我想显示新布局。如何在单击当前位置时为新布局充气 .. 这是我的代码

    public class CurrentLocationOverlay extends MyLocationOverlay {

    private Context mContext;
    private MapView mMapView;
    private Location mCurrentLocation;
    private MapController myMapController;
    double latitude, longitude;

    public CurrentLocationOverlay(Context context, MapView mapView) {
        super(context, mapView);
        mContext = context;
        mMapView = mapView;
    }

    @Override
    protected boolean dispatchTap() {
        // TODO handle a tap on "my location point", eg. display an option to
        // send SMS, make a call, add a picture to current location point.

            Toast.makeText(mContext, "Suppressing data readout", Toast.LENGTH_SHORT).show();

        return true;
    }
     /*LayoutInflater layoutInflater = (LayoutInflater) 
    mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LayoutParams lp = new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, p, LayoutParams.WRAP_CONTENT);
LinearLayout view = (LinearLayout)inflater.inflate(R.layout.map_overlay, null);
*/

}![enter image description here][1]
4

2 回答 2

0

请参阅以下链接,它可能对您有所帮助

关于在地图上添加布局作为叠加层的讨论

谷歌地图行车路线和覆盖

于 2011-12-19T07:55:28.160 回答
0

使用 ViewFlipper。

<?xml version="1.0" encoding="utf-8"?>
<ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/vf"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <include android:id="@+id/main1" layout="@layout/main1" />
    <include android:id="@+id/main2" layout="@layout/main2" />

</ViewFlipper>

假设 main1.xml 包含 MapView 并且 main2.xml 包含当您单击地图上的当前位置时要显示的布局。

ViewFlipper vf = (ViewFlipper)findViewById(R.id.vf);

然后使用此代码

@Override
protected boolean dispatchTap() {
    // TODO handle a tap on "my location point", eg. display an option to
    // send SMS, make a call, add a picture to current location point.
    vf.setDisplayChild(1); // to display main2.xml
        Toast.makeText(mContext, "Suppressing data readout", Toast.LENGTH_SHORT).show();

    return true;
}

我想它可能会对你有所帮助。

于 2011-12-17T10:19:46.320 回答