edi233
edi233

Reputation: 3031

Draw image in activity android

I have a activity where I have two imageViews. In onTouch I recognize which imageView was clicked. Now I have a question. How I can draw new very small image in place where I clicked. I know that onTouch i have getX() and getY() and I save this position when I touch the screen, but I don't know how I can draw image in place where I clicked. My image is in drawable resources. I need to use canvas or is better way. I need draw this picture and after that I need run animation this image.

edit1: How can I set positionX and positionY my image. I have position where I click but I don't know how I can set image in this coordinates.

Upvotes: 1

Views: 359

Answers (2)

stefan bachert
stefan bachert

Reputation: 9608

I see the following approach.

  • Replace the ImageView by a custom view derived from ImageView.
  • Override onDraw.
  • call super.onDraw to draw the image
  • paint your image using onDraw's canvas at the last touch position.

  • each time you get a touch, you need to invalidate the custom view

Upvotes: 0

you should have a image view with visible attribute of FALSE and after touch (or any event you want) set three attribute : visible = true; x = getX() and y = getY();

is it enough or explain more?

Upvotes: 3

Related Questions