开发者

Can I get the touch coordinates without using listener?

Is there any way to get the coordinates of touch (when user touch/multi-touch on activity) without using t开发者_如何学Gohe OnTouchListener event ? If it is possible, then kindly provide me any example.


Try this code:

int x, y;
TextView tv, tl;
FrameLayout fl;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    tv = (TextView) findViewById(R.id.textView);
    tv.setText("X Coordinate");

    tl = (TextView) findViewById(R.id.touchView);
    tl.setText("Y Coordinate");
}

@Override
public boolean onTouchEvent(MotionEvent e) {
    x = (int) e.getX();
    y = (int) e.getY();
    tv.setText("" + x);
    tl.setText("" + y);

    return true;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜