I am trying to drag the multiple image from popup to the canvas screen in android.I tryed one image to drag its working.But if the same image added next time ,the previous is disabled .if i click on the images the last added image is dragging .Can you help me how to do this one.
Here is my code
LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lparams.setMargins(260, 60, 260, 260);
img5 = new ImageView(this);
img5.setMaxHeight(50);
img5.setMaxWidth(50);
img5.setLayoutParams(lparams);
img5.setImageResource(R.drawable.crown);
img5.setOnTouchListener(new View.OnTouchListener() {
float x,y=0.0f;
boolean moving=false;
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
switch(arg1.getAction()){
case MotionEvent.ACTION_DOWN:
moving=true;
break;
case MotionEvent.ACTION_MOVE:
if(moving){
x=arg1.getRawX()-img5.getWidth()/2;
y=arg1.getRawY()-img5.getHeight()*3/2;
img5.setX(x);
img5.setY(y);
}
break;
case MotionEvent.ACTION_UP:
moving=true;
break;
}
return true;
}
});
frame.addView(img5);
}