【问题标题】:How can i open new layout when i click on current location in map in android当我在android中单击地图中的当前位置时如何打开新布局
【发布时间】:2011-12-17 06:10:19
【问题描述】:

我想在单击 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]

【问题讨论】:

    标签: android view android-inflate layout-inflater


    【解决方案1】:

    使用 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;
    }
    

    我想这可能对你有帮助。

    【讨论】:

    • 不,它不起作用..我想显示相同的效果,这是 android 地图中的默认设置,单击当前位置显示小布局..请检查您的 android 地图应用程序。当我们点击当前位置时,它会显示小布局。
    • 我认为你必须显示新的布局,当你点击地图时,它会改变当前的屏幕。现在我明白了你在问什么。我认为使用 Map Overlay 我们可能会获得与 Maps 应用程序相同的效果。试一次。我也会检查的。感谢您的评论。再见
    • 感谢您帮助我...但我现在希望您了解...我认为只有使用 MyLocationOverlay 才有可能。处理当前位置的 Click 事件。如提及评论。
    【解决方案2】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      • 2017-01-09
      • 2013-10-03
      • 1970-01-01
      • 2018-02-22
      相关资源
      最近更新 更多