Markers|Developer reference to bon-app-etit
private void setMarker(final LatLng gps, final String title, final String desc, int resource)
{
MarkerOptions markerOpt = new MarkerOptions()
.position(gps)
.title(title)
.snippet(desc)
.icon(BitmapDescriptorFactory.fromResource(resource));
mGoogleMap.addMarker(markerOpt);
InfoWindowAdapter iwa = new InfoWindowAdapter() {
private final View contents = getActivity().getLayoutInflater().inflate(R.layout.custom_marker, null);
@Override
public View getInfoWindow(Marker arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public View getInfoContents(Marker marker) {
String title = marker.getTitle();
TextView txtTitle = ((TextView) contents.findViewById(R.id.txtInfoWindowDesc));
if (title != null) {
SpannableString titleText = new SpannableString(title);
txtTitle.setText(titleText);
} else {
txtTitle.setText("");
}
TextView txtType = ((TextView) contents.findViewById(R.id.txtInfoWindowGps));
txtType.setText(marker.getSnippet());
return contents;
}
};
mGoogleMap.setInfoWindowAdapter(iwa);
}
xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingRight="10dp">
<ImageView
android:id="@+id/ivInfoWindowMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:adjustViewBounds="true"
android:src="@drawable/tab_overview2">
</ImageView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/txtInfoWindowDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#ff000000"
android:textSize="14dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/txtInfoWindowGps"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:textColor="#ff7f7f7f"
android:textSize="14dp"/>
</LinearLayout>
</LinearLayout>

0 意見:
張貼留言