Android 带按钮的Skobbler注释
我正在创建一个Skobbler注释,如下所示:Android 带按钮的Skobbler注释,android,onclick,onclicklistener,skmaps,Android,Onclick,Onclicklistener,Skmaps,我正在创建一个Skobbler注释,如下所示: markerCoords = mapView.pointToCoordinate(skScreenPoint); //gives us the coordinate SKAnnotation annotation = new SKAnnotation(11); SKAnnotationView view = new SKAnnotationView(); View v = getLayoutInflater().inflate(R.layout
markerCoords = mapView.pointToCoordinate(skScreenPoint); //gives us the coordinate
SKAnnotation annotation = new SKAnnotation(11);
SKAnnotationView view = new SKAnnotationView();
View v = getLayoutInflater().inflate(R.layout.annotation_marker, null, false);
v.findViewById(R.id.btn_destination).setOnClickListener(destListener);
v.findViewById(R.id.btn_origin).setOnClickListener(originListener);
view.setView(v);
annotation.setAnnotationView(view);
annotation.setLocation(mapView.pointToCoordinate(skScreenPoint));
annotation.setMininumZoomLevel(1);
mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_POP_OUT);
视图R.layout.annotation\u标记
包含两个按钮,但我无法点击/单击它们。我的点击穿过注释并点击地图(我已经检测到了)。我尝试在膨胀视图时对其使用requestFocus(),但没有效果。我还有android:clickable='true'
在xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="200dp"
android:layout_height="110dp"
android:layout_gravity="center_horizontal">
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Origin"
android:id="@+id/btn_origin"
android:layout_gravity="right"
android:focusable="true"
android:clickable="true"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:text="Destination"
android:id="@+id/btn_destination" />
</LinearLayout>
如何让单击事件点击按钮而不是底层映射?因为onClick事件没有发生,为了在地图上的不同视图上启用事件,解决方案是使用AnnotationView和onAnnotationSelected回调上的execute操作将它们合并到不同的注释中(因此每个注释应该有一个视图) 为了以自然的方式触发事件,必须为注释设置相应的偏移量,以便在单击实际视图而不是注释的扩展时触发onAnnotationSelected回调
@Override
public void onSurfaceCreated(SKMapViewHolder mapHolder) {
….
SKAnnotation annotation = new SKAnnotation(137);
SKAnnotationView annotationView = new SKAnnotationView();
View v = getLayoutInflater().inflate(R.layout.bug_2_btn_layout,null,false);
annotationView.setView(v);
annotation.setAnnotationView(annotationView);
annotation.setLocation(new SKCoordinate(52.520008,13.404954));
annotation.setMininumZoomLevel(1);
double viewToLayoutRatio = getResources().getDimension(R.dimen.originBtn_width)/getResources().getDimension(R.dimen.annotationLayout_width);
annotation.setOffset(new SKScreenPoint((float) (annotation.getOffset().getX()-(viewToLayoutRatio*getResources().getDimension(R.dimen.originBtn_width))), (float) (annotation.getOffset().getY()+(viewToLayoutRatio/3)*getResources().getDimension(R.dimen.originBtn_width))));
mapView.addAnnotation(annotation, SKAnimationSettings.ANIMATION_POP_OUT);
…
}
@Override
public void onAnnotationSelected(final SKAnnotation annotation) {
switch (annotation.getUniqueID()) {
…
case 137:
Toast.makeText(getApplicationContext(),"Annotation was clicked",Toast.LENGTH_SHORT);
View v = getLayoutInflater().inflate(R.layout.bug_2_btn_layout,null,false);
originClicked(v);
break;
}
}
您需要设置图像的中心点-点击注释将取决于此值。@SylviA图像的中心点是什么,如何设置此值?你说的是什么形象?谢谢,我想我误解了。我在考虑这个场景:这个问题已经报告给了侦察开发团队。@SylviA非常感谢,我希望很快能收到他们的回复。目前,我不得不使用几个不同的注释作为不同的按钮,并使用onAnnotationSelected回调来解决这个问题。