您好,我在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;
}