I am trying to place a button dynamically on an Image when a user touches it. Can someone help.
I've tried this code but every time the button gets disappeared
rl.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
x = rl.getX();
y=rl.getY();
int i = x.intValue();
int j = y.intValue();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(i,j);
rd1.setLayoutParams(layoutParams);
return true;
}
});
Try this
x=(int)event.getx();
y=(int)event.gety();
and set these x,y values to your layout params
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.