【发布时间】:2014-06-01 01:42:56
【问题描述】:
基本上问题是当我打开任何标记时,出现的信息窗口总是有相同的图像,但标题和 sn-p 没有问题。
我不知道每个标记特定于不同的图像,但不知道如何。 (图片在文件夹抽屉里)
这是我的代码: Fragmentavtivity.java
public class Fragment17 extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment17, container, false);
return rootView;
}
@Override
public void onViewCreated(View v, Bundle savedInstanceState){
super.onViewCreated(v, savedInstanceState);
final LatLng Initial = new LatLng(-34.673009, -58.474111);
final LatLng FADU = new LatLng(-34.542163, -58.443716);
final LatLng UNO = new LatLng(-34.524924, -58.576421);
final LatLng DOS = new LatLng(-34.755415, -58.577794);
GoogleMap googlemap;
googlemap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map17)).getMap();
googlemap.setMyLocationEnabled(true);
googlemap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
CameraUpdate update = CameraUpdateFactory.newLatLngZoom(Initial, 10);
googlemap.animateCamera(update);
googlemap.addMarker(new MarkerOptions().position(FADU).title("FADU").snippet("Facultad de Arquitectura, Diseño y Urbanismo").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
googlemap.addMarker(new MarkerOptions().position(UNO).title("TEOREMA").snippet("san matin 1245"));
googlemap.addMarker(new MarkerOptions().position(DOS).title("El Mundo del Acrilico").snippet("san benito 2144/"));
googlemap.setInfoWindowAdapter(new InfoWindowAdapter() {
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater(null).inflate(R.layout.infowindow, null);
TextView titulo = (TextView) v.findViewById(R.id.titulo);
TextView direccion = (TextView) v.findViewById(R.id.direccion);
ImageView imagen = ((ImageView)v.findViewById(R.id.imagen));
titulo.setText(marker.getTitle());
direccion.setText(marker.getSnippet());
imagen.setImageDrawable(getResources().getDrawable(R.drawable.teorema));
return v;
}
@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
});
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onDestroyView() {
super.onDestroyView();
Fragment fragment = (getFragmentManager().findFragmentById(R.id.map17));
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}
和infowindow.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/imagen"
android:layout_width="65dp"
android:layout_height="99dp"
android:contentDescription="@string/app_name"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal|center"
android:textSize="15sp"
android:textStyle="bold" />
<TextView
android:id="@+id/direccion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal|center"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
还有一个问题:
就像我对每个标记的每个信息窗口所做的那样,单击时打开一个不同的片段。
谢谢。
【问题讨论】:
-
您无需将标题更改为 (SOLVED)。 SO 将自行处理(黄色数字)。
标签: android eclipse google-maps google-maps-markers google-maps-android-api-2