<i id='SNzNW'><tr id='SNzNW'><dt id='SNzNW'><q id='SNzNW'><span id='SNzNW'><b id='SNzNW'><form id='SNzNW'><ins id='SNzNW'></ins><ul id='SNzNW'></ul><sub id='SNzNW'></sub></form><legend id='SNzNW'></legend><bdo id='SNzNW'><pre id='SNzNW'><center id='SNzNW'></center></pre></bdo></b><th id='SNzNW'></th></span></q></dt></tr></i><div id='SNzNW'><tfoot id='SNzNW'></tfoot><dl id='SNzNW'><fieldset id='SNzNW'></fieldset></dl></div>
        <bdo id='SNzNW'></bdo><ul id='SNzNW'></ul>
      <legend id='SNzNW'><style id='SNzNW'><dir id='SNzNW'><q id='SNzNW'></q></dir></style></legend>

      <tfoot id='SNzNW'></tfoot>

    1. <small id='SNzNW'></small><noframes id='SNzNW'>

      1. MapView 中的 OnTouch 仅在第一次触发

        时间:2023-08-31

          <small id='cZAYw'></small><noframes id='cZAYw'>

              <bdo id='cZAYw'></bdo><ul id='cZAYw'></ul>
                <tbody id='cZAYw'></tbody>
            • <i id='cZAYw'><tr id='cZAYw'><dt id='cZAYw'><q id='cZAYw'><span id='cZAYw'><b id='cZAYw'><form id='cZAYw'><ins id='cZAYw'></ins><ul id='cZAYw'></ul><sub id='cZAYw'></sub></form><legend id='cZAYw'></legend><bdo id='cZAYw'><pre id='cZAYw'><center id='cZAYw'></center></pre></bdo></b><th id='cZAYw'></th></span></q></dt></tr></i><div id='cZAYw'><tfoot id='cZAYw'></tfoot><dl id='cZAYw'><fieldset id='cZAYw'></fieldset></dl></div>
              <legend id='cZAYw'><style id='cZAYw'><dir id='cZAYw'><q id='cZAYw'></q></dir></style></legend>
            • <tfoot id='cZAYw'></tfoot>

                  本文介绍了MapView 中的 OnTouch 仅在第一次触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试在我的 MapView 中实现双击缩放功能.该事件总是第一次触发,但以后不会触发.下面是我的代码.我感觉这与第一次触发事件后地图控制器丢失有关.

                  I'm trying to implement a double-tap zoom like function in my MapView. The event always fires the first time, but never subsequent times. Below is my code. I have a feeling it has something to do with the map controller getting lost after the first time the event is fired.

                  import android.os.Bundle;
                  import android.view.MotionEvent;
                  import android.view.View;
                  import android.view.View.OnTouchListener;
                  import com.google.android.maps.MapActivity;
                  import com.google.android.maps.MapController;
                  import com.google.android.maps.MapView;
                  
                  public class mainmap extends MapActivity implements OnTouchListener{
                  
                      long lasttime = -1;
                      MapController mapc;
                  
                      @Override
                      public void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          setContentView(R.layout.main);
                          MapView mapView = (MapView) findViewById(R.id.mapview);
                          mapView.setBuiltInZoomControls(true);
                          mapc = mapView.getController();
                          mapView.setOnTouchListener(this);       
                      }
                  
                      @Override
                      protected boolean isRouteDisplayed() {
                          // TODO Auto-generated method stub
                          return false;
                      }
                  
                      @Override
                      public boolean onTouch(View v, MotionEvent event) {
                          if (event.getAction() == MotionEvent.ACTION_DOWN){
                  
                              if(event.getEventTime()-lasttime<2000){
                                  mapc.zoomInFixing((int)event.getX(),(int)event.getY());             
                              }
                          }       
                          lasttime=event.getEventTime();
                          return true;
                      }
                  
                    }
                  

                  我还尝试编辑 OnTouch 方法以将传入的 View 转换为 MapView,在触发事件时获取控制器.但是,在触发第一个事件而不是后续事件的情况下,我得到了相同的结果.

                  I have also tried editing the OnTouch method to cast the incoming View to a MapView, getting the controller while the event is fired. However, I get the same results where the first event is fired but not subsequent ones.

                  public boolean onTouch(View v, MotionEvent event) {
                          if (event.getAction() == MotionEvent.ACTION_DOWN){
                  
                              if(event.getEventTime()-lasttime<2000){
                                  ((MapView)v).getController().zoomInFixing((int)event.getX(), (int)event.getY());                
                              }
                          }       
                          lasttime=event.getEventTime();
                          return true;
                      }
                  

                  为了尽可能简单,我删除了 OnTouch 方法中的所有代码,并将其编程为简单地显示一条小的 toast 消息.

                  Being as basic as possible, I cut out all of the code in the OnTouch method and programmed it to simply display a small toast message.

                  public boolean onTouch(View v, MotionEvent event) {
                          if (event.getAction() == MotionEvent.ACTION_DOWN){
                  
                                 Toast.makeText(this,"Down!",Toast.LENGTH_SHORT).show();
                  
                          }       
                  
                          return true;
                  }
                  

                  这按预期工作,每次触摸 MapView 时都会显示 Toast.

                  This works as expected, displaying the Toast each time the MapView is touched.

                  我不明白为什么在这种情况下事件会正确触发,但在我之前的实现中却不会.

                  I don't understand why the event will fire properly in this case but not in my previous implementation.

                  推荐答案

                  如果你使用这个方法 "mapView.setBuiltInZoomControls(true);" 那么你的 touch 是立即工作.

                  If you are using this method "mapView.setBuiltInZoomControls(true);" then your touch is working at once .

                  请删除该行并检查我确定它会起作用..

                  Please remove that that line and check I am sure it will work..

                  在某些情况下,如果您想要 BuiltInZoomControls,那么您可以使用 OnTouch 的 Overlay 方法,如下所示..

                  In some case if you want BuiltInZoomControls then you can you OnTouch method of Overlay like as below..

                  public class MapOverlay extends Overlay {
                  
                      public MapOverlay(Context ctx) {super(ctx);}
                  
                      @Override
                      protected void draw(Canvas c, MapView osmv, boolean shadow) { }
                  
                      @Override
                      public boolean onTouchEvent(MotionEvent e, MapView mapView) {
                          //Write yout touch code here..
                          return false;
                      }
                  }
                  

                  这篇关于MapView 中的 OnTouch 仅在第一次触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:单击外部时隐藏 MAAttachedWindow 下一篇:iOS - 未收到 UIEventTypeRemoteControl 事件

                  相关文章

                  最新文章

                    <small id='gjcOf'></small><noframes id='gjcOf'>

                  1. <i id='gjcOf'><tr id='gjcOf'><dt id='gjcOf'><q id='gjcOf'><span id='gjcOf'><b id='gjcOf'><form id='gjcOf'><ins id='gjcOf'></ins><ul id='gjcOf'></ul><sub id='gjcOf'></sub></form><legend id='gjcOf'></legend><bdo id='gjcOf'><pre id='gjcOf'><center id='gjcOf'></center></pre></bdo></b><th id='gjcOf'></th></span></q></dt></tr></i><div id='gjcOf'><tfoot id='gjcOf'></tfoot><dl id='gjcOf'><fieldset id='gjcOf'></fieldset></dl></div>
                      <bdo id='gjcOf'></bdo><ul id='gjcOf'></ul>

                    1. <legend id='gjcOf'><style id='gjcOf'><dir id='gjcOf'><q id='gjcOf'></q></dir></style></legend>
                      <tfoot id='gjcOf'></tfoot>