How to resize image when clicked

I am currently developing an application for Android, and I would like to achieve an effect for which I could not find an answer, even after some searching.

The effect that I would like to get is above the image. Usually, when you click on an image, you apply some kind of hue to the image to show some kind of feedback, but I would like to go a little further, I would not want to apply hue, but the scale of sorting is on the image scale.

eg. I have the following image: Normal Image , and if I click on the image (and while I hold it), I would like the image to be compressed a little, for example, a Pressed image

NB- The black part will not be part of the image, but part of the background. The image will only be a blue square.

Thanks for any help! :)

PS- I was not able to post images here because I do not have enough reputation.

+6
source share
1 answer

You need to install the onTouchListener of your ImageView, which displays the image so that it replaces the displayed image. This is the listener that starts when you click or release the image (in this case, the image).

Code example:

ImageView iv = (ImageView)findViewById(R.id.my_image_view); iv.setOnTouchListener(new ImageView.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { if (e.getAction()==MotionEvent.ACTION_DOWN) // Write code here that sets the imageview to display the pressed image else if (e.getAction()==MotionEvent.ACTION_UP) // Write code here that sets the imageview to display the unpressed image } }); 

Link to onTouchListener: http://developer.android.com/reference/android/view/View.OnTouchListener.html

ImageView link (to replace the displayed image): http://developer.android.com/reference/android/widget/ImageView.html

0
source

All Articles