问题描述:

This question already has an answer here:

  • Fling gesture detection on grid layout

    17 answers

  • Get the co-ordinates of a touch event on Android

    4 answers

网友答案:

Try this,

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final TextView textView = (TextView)findViewById(R.id.textView);
    // this is the view on which you will listen for touch events
    final View touchView = findViewById(R.id.touchView);
    touchView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            textView.setText("Touch coordinates : " +
                String.valueOf(event.getX()) + "x" + String.valueOf(event.getY()));
                return true;
        }
    });
}
网友答案:

If Using PhoneGap you can use the HTML/JS. Refer Below

recommend this link- http://miloq.blogspot.in/2011/05/coordinates-mouse-click-canvas.html

<style type="text/css">

#canvas{background-color: #000;}

</style>

<script type="text/javascript">

  document.addEventListener("DOMContentLoaded", init, false);

  function init()
 {
    var canvas = document.getElementById("canvas");
    canvas.addEventListener("mousedown", getPosition, false);
  }

 function getPosition(event)
 {
var x = new Number();
var y = new Number();
var canvas = document.getElementById("canvas");

if (event.x != undefined && event.y != undefined)
{
  x = event.x;
  y = event.y;
}
else // Firefox method to get the position
 {
     x = event.clientX + document.body.scrollLeft +
        document.documentElement.scrollLeft;
      y = event.clientY + document.body.scrollTop +
      document.documentElement.scrollTop;
     }

x -= canvas.offsetLeft;
y -= canvas.offsetTop;

    alert("x: " + x + "  y: " + y);
  }

</script>
相关阅读:
Top