问题描述
我想有一个 自定义信息窗口
显示在标记
点击。
我希望它是这样的:
ImageView
TextView
TextView
TextView
Button Button
我看到这个其他的职位问题,但它仍然是令人困惑的。
I saw other's post question on this, but it's still confusing.
推荐答案
关于ImageView的和TextView的,试试这个:
About ImageView and TextView, try this:
设置一个信息窗口的布局: infowindowlayout.xml
set an infowindow layout: 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 (这是一个标记的例子,但你也可以用这个为他人标记):
In your MapActivity (this is an example for one marker, but you can use this also for others markers):
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;
}
关于按钮,ImageButtons等也没有办法。该说:
由于在信息窗口的previous一节中提到,信息窗口不是实时视图,而该视图呈现为一个图像到地图上。这样一来,你在视图上设置的所有听众都被忽略,你不能对视图的各个部分的点击事件进行区分。建议您不要对交互式组件 - 如按钮,复选框或文本输入 - 。您的自定义信息窗口中
无论如何,这似乎有一个解决方案,请参阅。我不知道这是否是适用与我的code,但它似乎按钮和imagebuttons工作。
Anyway, it seems there is a solution, see this answer here. I don't know if it is applicable with my code, but it seems work with buttons and imagebuttons.
这篇关于的谷歌定制的信息窗口地图Android版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!