1

I am working on android 2.3.3 ++ How do i show an image in arbitrary position (x, y)? I've implemented view.onLongClickListener: to_button.setOnLongClickListener(new OnLongClickListener(){

        @Override
        public boolean onLongClick(View v) {
            showCircle(v, x, y);
            return true;
        }

Now i would like to show a circle (drawable) on position x, y. How do i go about doing this in the most efficient way.

JY2k
  • 2,879
  • 1
  • 31
  • 60
  • see also https://stackoverflow.com/questions/6530350/android-press-longclicklistener-get-x-y-coordinates-ontouchlistener – Suragch Oct 07 '17 at 10:54

2 Answers2

3

Implements onTouch method for you view, get the x and y, draw circle when onLongClick fired. Try this:

int x;
int y;
v.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View arg0, MotionEvent ev) {
        if(ev.getAction() == MotionEvent.ACTION_DOWN){
            x = ev.getX();
            y = ev.getY();
        }
        return false;
    }
})
v.setOnLongClickListener(new OnLongClickListener() {

    @Override
    public boolean onLongClick(View v) {
        showCircle(v, x, y);
        return false;
    }
});
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
user2652394
  • 1,686
  • 1
  • 13
  • 15
  • @JonathanYarkoni, create your own View extends from `View`, implements `onDraw` method which can draw a circle/rect/drawable in a specified position, make a boolean for drawing or not drawing the circle, then every time `onLongClick` fire, turn the boolean to drawing, refresh your view by `v.invalidate()`. Hope this helps. – user2652394 Sep 15 '13 at 16:46
0

If your question is how to draw a circle in Android, then you should take a look at this: Draw circle in android

Community
  • 1
  • 1
elvitucho
  • 126
  • 6