I want to implement something like this where when I should be able to drag selecting icon from male to female and vise versa. Currently I am doing this by handling click even on text of male or female and replacing the image where the selecting icon is on appropriate side. How could I achieve it.
Asked
Active
Viewed 369 times
1 Answers
0
Yes you can do what you want.
First You just need to get left margin of your white image.
second set touch listener on imageview and on Tochevent just add some value to left margin of imageview Thats it. It moves as your value added.
For example:
ImageView iv=(ImageView)findViewById(R.id.myImageView);
LayoutParam params=iv.getLayoutParams();
int left=params.leftMargin;
iv.setonTouchListener(new View.onTouchListener{
@override
boolean onTouch(MotionEvent event){
super(event);
if(female){
params.leftMargin = left + 20;
}else{
params.leftMargin = left - 20;
}
iv.setLayoutParams(params);
return true;
}
}
);
good luck...

WonderSoftwares
- 2,800
- 1
- 15
- 21
-
i didnt get the condition if(female) {}else{},are you referring if the selected gender is female then onTouch event , left margin should be changed but in this case it might be possible that user doesnt drag the image to right side and then also it will be shifted to right side. – Jun 14 '14 at 13:12
-
yes, then you can add Motionevent cases for listen move events, like this: ontouch(){ switch(event.getAction()){ case MotionEvent.ACTION_MOVE: //DO YOUR CODE AS ABOVE ANSWER break; } } – WonderSoftwares Jun 14 '14 at 13:17