Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
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);

}
Posted
Updated 19-Nov-14 23:51pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900