我想让点击custom info window
出现marker
。
我希望它是这样的:
ImageView
TextView
TextView
TextView
Button Button
我看到了其他人对此的提问,但仍然令人困惑。
关于ImageView和TextView,请尝试以下操作:
设置信息窗口布局:infowindowlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#FFFFFF" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
在您的MapActivity中(这是一个标记的示例,但是您也可以将其用于其他标记):
public class MapActivity extends Activity {
private GoogleMap mMap;
private Marker Somewhere;
private int markerclicked;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
...
...
final LatLng somewhere = new LatLng(..., ...);
Somewhere=mMap.addMarker(new MarkerOptions()
.position(somewhere)
.title("YOUR TITLE")
.snippet("INFO")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pin)));
...
...
...
mMap.setInfoWindowAdapter(new InfoWindowAdapter() {
// Use default InfoWindow frame
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
// Defines the contents of the InfoWindow
@Override
public View getInfoContents(Marker arg0) {
// Getting view from the layout file infowindowlayout.xml
View v = getLayoutInflater().inflate(R.layout.infowindowlayout, null);
LatLng latLng = arg0.getPosition();
ImageView im = (ImageView) v.findViewById(R.id.imageView1);
TextView tv1 = (TextView) v.findViewById(R.id.textView1);
TextView tv2 = (TextView) v.findViewById(R.id.textView2);
String title=arg0.getTitle();
String informations=arg0.getSnippet();
tv1.setText(title);
tv2.setText(informations);
if(onMarkerClick(arg0)==true && markerclicked==1){
im.setImageResource(R.drawable.yourdrawable);
}
return v;
}
});
}
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(Somewhere))
{
markerclicked=1;
return true;
}
return false;
}
关于按钮,图像按钮等,是没有办法的。该文件说:
如上一节中有关信息窗口的部分所述,信息窗口不是实时视图,而是将视图作为图像渲染到地图上。结果,您在视图上设置的所有侦听器都将被忽略,并且您无法区分视图各个部分上的单击事件。建议您不要在自定义信息窗口中放置交互式组件,例如按钮,复选框或文本输入。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句