我正在使用的代码:
@Override
public boolean onTouch(View v, final MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN){
final RelativeLayout urLayoutId=(RelativeLayout) findViewById(R.id.RelativeCoche);
final ImageView imv=new ImageView(MainActivity.this);
imv.setImageResource(R.drawable.info);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(Math.round(event.getX()),
Math.round(event.getY()), 0, 0);
imv.setLayoutParams(params);
return true;
}
});