0
我想获得android studio xml的背景图像的实际触摸像素。当触摸位置处于所需坐标的范围内时,我试图开始一个新的活动。谢谢!如何在android studio xml中获取像素的位置?
我想获得android studio xml的背景图像的实际触摸像素。当触摸位置处于所需坐标的范围内时,我试图开始一个新的活动。谢谢!如何在android studio xml中获取像素的位置?
您可以在背景图像上为您的布局设置onTouchListener()。
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
mainLayout.setOnTouchListener(this); // in this case activity should implements View.OnTouchListener
然后使用类似[获取的x,特定像素的y位置]的那
public boolean onTouch(View v, MotionEvent event) {
Point touchPlace = new Point();
touchPlace.set(event.getX(), event.getY());
}
可能的复制(http://stackoverflow.com/questions/9926055/get-xy-position -of-A-特定像素) –