首页 / 浏览问题 / 移动GIS / 问题详情
DynamicView 上弹窗
13EXP 2017年08月31日

您好,我在DynamicView中添加了多个 DynamicPoint, 然后我设置了DynamicPoint的监听事件,点击时弹出一个PopupWindow, 这个在Android 7.0上可以弹出,但在6.0上无法弹出。部分代码如下:

//创建DynamicView
m_dynamicLayer = new DynamicView(this, m_mapControl.getMap());
m_mapview.addDynamicView(m_dynamicLayer);
//添加element
DynamicPoint element = new DynamicPoint();
element.addPoint(point2Ds.getItem(0));
DynamicStyle style = new DynamicStyle();
style.setBackground(BitmapFactory.decodeResource(getResources(), elementInfo.getBackgroundResId()));
element.setStyle(style);
element.setOnClickListenner(new DynamicElement.OnClickListener() {
    @Override
    public void onClick(DynamicElement element) {
        if (mPopupWindow != null && mPopupWindow.isShowing()) {
            mPopupWindow.dismiss();
        }

        Point2Ds geoPoints = element.getGeoPoints();
        Point2Ds point2ds = new Point2Ds();
        point2ds.add(geoPoints.getItem(0));
        //根据投影坐标找出屏幕上的坐标
        Point point = m_mapControl.getMap().mapToPixel(point2ds.getItem(0));
        //将投影坐标转为地理坐标
        boolean inverse = CoordSysTranslator.inverse(point2ds, prjCoordSys);
        LogUtil.i("inverse: " + inverse);
        Point2D p = point2ds.getItem(0);
        String text = "经度: " + p.getX() + "\n" + "纬度: " + p.getY();
       //弹出
        mPopupWindow = create(point, text);
    }
});

//创建PopupWindow

public PopupWindow create(Point point2D, String text) {
    PopupWindow popupWindow = new PopupWindow(this);
    popupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    TextView textView = new TextView(this);
    textView.setText(text);
    popupWindow.setContentView(textView);
    popupWindow.setBackgroundDrawable(new ColorDrawable(0x000000ff));
    popupWindow.setOutsideTouchable(false);
    popupWindow.setFocusable(true);
    popupWindow.showAsDropDown(m_dynamicLayer, (int) point2D.getX(),
            (int) point2D.getY());
    return popupWindow;
}

1个回答

这个PopupWindow类是Android本身的接口,其不弹框是否和iMobile中类有关联;建议你在百度上百度一下不弹框的原因,我百度了一下有相关的提问和解决方案,可能是PopupWindow没法获取焦点,比如可以参考:http://www.cnblogs.com/chlewsz/p/4383958.html或者http://tieba.baidu.com/p/4761944381

2,042EXP 2017年09月01日
...