【发布时间】:2015-03-23 18:59:41
【问题描述】:
我已经使用 google android map v2 实现了自定义标记。它在某些设备上运行良好,并且在某些设备上自定义标记似乎是空白的。我的自定义标记 xml 文件如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/markerText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/markerText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/markerText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/markerText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/markerImage1"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/ic_action_call"
android:contentDescription="Map Info"/>
<TextView
android:id="@+id/markerText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tap Here for more."
/>
</LinearLayout>
</LinearLayout>
我已经在 java 文件中实现了它,如下所示:
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.fp_map);
map = fm.getMap();
if(map != null){
map.setIndoorEnabled(false);
map.setOnCameraChangeListener(getCameraChangeListener());
//add custom window here
map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = null;
try {
if(!marker.getTitle().equalsIgnoreCase("diff")) {
try {
v = getLayoutInflater().inflate(R.layout.info_window, null);
TextView title = (TextView) v.findViewById(R.id.markerText1);
TextView midMsg = (TextView) v.findViewById(R.id.markerText2);
TextView BelowMsg1 = (TextView) v.findViewById(R.id.markerText3);
TextView BelowMsg2 = (TextView) v.findViewById(R.id.markerText4);
String[] data = marker.getSnippet().split("\\|\\|");
title.setText(marker.getTitle());
midMsg.setText(data[0]);
BelowMsg1.setText("check here:" + data[2]);
BelowMsg2.setText(data[1] + "check here also");
return v;
} catch (Exception e) {
String error = e.getMessage();
}
} else {
return null; //so that normal view can be generted.
}
} catch (Exception e){
String error1 = e.getMessage();
return null;
}
return v;
}
});
}
最后我添加如下标记:
BitmapDescriptor loaded_icon;
loaded_icon = BitmapDescriptorFactory.fromResource(R.drawable.smiley_f);
map.addMarker((new MarkerOptions().position(new LatLng(Double.parseDouble(data[1]), Double.parseDouble(data[2])))
.title(data[0])
.snippet(data[5] + "||" + data[6] + "||" + data[7])
.icon(loaded_icon)))
.showInfoWindow();
上述添加标记代码在循环中,因此可以向用户显示不同的标记。现在我的问题是对于许多用户来说,它工作得很好,但对于某些手机(例如 HTC WILDFIRE),它给出了空白屏幕作为我在 xml 文件中提到的图像的标记。
我也遇到以下错误,不确定是否与上述问题有关。 此错误在打开地图页面之前就开始出现。
E/copybit?打开帧缓冲区时出错 errno=13(权限被拒绝)
W/Adreno200-EGLSUB? <342>342>
>
标签: android google-maps