tags:

views:

149

answers:

1

I have a program in which I would like to place an image at the coordinates of a touch event. I have the coordinates now I just need help with placing an image there. I will be using a drawable.

Edit** I also want to overlay it over another image. I cant find any documentation on this what so ever. I would think it should be easy.

Can anyone help me?

EDIT** Got it, now I just have to figure out how to get the middle of the image at the touch spot and not the top left corner:

 final View touchView2 = findViewById(R.id.ImageView02);
    touchView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.v("x,y",event.getY()+","+event.getX());
            touchView2.bringToFront();
            int y = (int)event.getY();
            int x = (int)event.getX();

            touchView2.layout(x, y, x+48, y+48);
                return true;
        }
    });
A: 
Drawable recycle_bin = context.getResources().getDrawable(android.R.drawable.ic_menu_delete);
int w = recycle_bin.getIntrinsicWidth();
int h = recycle_bin.getIntrinsicHeight();
int x = getWidth()/2 - w/2;
int y = getHeight() - h - 5;

recycle_bin.setBounds( x, y, x + w, y + h );
recycle_bin.draw( canvas );

that's how I draw a recycle bin icon at the bottom center

zed_0xff
Not quite working for me here, but thanks.
dweebsonduty