First make your class extends a ViewGroup
like RelativeLayout
and FrameLayout
in your case.
Then, on the touch event, create a Button
(or a ImageView
and setOnClickListener()
), adjust the position of the button with margins on the view LayoutParams
and add the button to the layout via addView()
.
Edit: The button creation will be like this on onTouchEvent()
:
Point p = new Point();
p.x = (int)event.getX();
p.y = (int)event.getY();
Button button = new Button(context);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(buttonWidth, buttonHeight);
params.leftMargin = p.x;
params.topMargin = p.y;
addView(button, params);
Also change this to be inside ACTION_UP
to prevent creating multiple buttons on long pressing.