我正在创建一个应用程序,需要将图像放在用户点击的位置的屏幕上。当用户第二次点击时,屏幕上显示的第一个图像消失了..
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
int x = (int) motionEvent.getX();
int y = (int) motionEvent.getY();
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
ImageView iv = new ImageView(getApplicationContext());
lp.setMargins(x, y, 0, 0);
iv.setLayoutParams(lp);
iv.setImageDrawable(getResources().getDrawable(R.drawable.a));
((ViewGroup) view).addView(iv);
}