Java 通过触摸将图像插入触摸坐标处的屏幕

Java 通过触摸将图像插入触摸坐标处的屏幕,java,android,Java,Android,我正在制作一个应用程序,需要在屏幕上用户单击的位置放置一个图像。当用户第二次单击时,屏幕上出现的第一个图像消失 if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { int x = (int) motionEvent.getX(); int y = (int) motionEvent.getY(); RelativeLayout.LayoutParams lp = new RelativeLayout.La

我正在制作一个应用程序,需要在屏幕上用户单击的位置放置一个图像。当用户第二次单击时,屏幕上出现的第一个图像消失

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);
}

我插入图像的代码在这里发布您的代码。如果(motionEvent.getAction()==motionEvent.ACTION_DOWN){int x=(int)motionEvent.getX();int y=(int)motionEvent.getY();RelativeLayout.LayoutParams lp=新建RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_内容,RelativeLayout.LayoutParams.WRAP_内容);ImageView iv=新建ImageView(getApplicationContext());lp.setMargins(x,y,0,0);iv.setLayoutParams(lp);iv.setImageDrawable(getResources().getDrawable(R.drawable.a));((ViewGroup)view.addView(iv);#请。。。。。。