如何在android studio xml中获取像素的位置?

时间:2016-03-04 14:47:06

标签: android xml position touch pixel

我正在尝试获取android studio xml的背景图像的实际触摸像素。当触摸位置处于所需坐标的边界时,我正在尝试开始新的活动。谢谢!

1 个答案:

答案 0 :(得分:3)

您可以使用背景图片在布局上设置onTouchListener()。

RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
mainLayout.setOnTouchListener(this); // in this case activity should implements  View.OnTouchListener

然后使用类似的东西

public boolean onTouch(View v, MotionEvent event) {
    Point touchPlace = new Point();
    touchPlace.set(event.getX(), event.getY());
}