0

This is my requirement in Android . I need to display a tiny image. When the user presses the image the image should zoom in slightly and go back to it's original position, thus giving the impression that the image has been clicked. How do I go about doing this? (I tried using 2 different images (using image selector) in imageview, but both images got scaled to the view size and hence there was no animation visible)

Please help.

Regards, Sam

sammydude
  • 135
  • 7
  • 18

1 Answers1

0

If you want only increase image size when it pressed (without animation) - selector is right way, and it should work.

May be you set wrong layout params or scaleType for ImageView.

If you want to see smooth animation, when user click on imageview, you should add onClickListener to your ImageView and add proper Animation on onClick handler.

AlexKorovyansky
  • 4,873
  • 5
  • 37
  • 48
  • Thanks for your response Korovyansk! – sammydude Feb 06 '11 at 08:17
  • Korovyansk, Pasted my code in the previous comments. Let me know if I'm doing anything wrong in the code. Also could you give me some pointers on handling animation on onClick handler. Sorry, I'm a newbie trying hard! :-) – sammydude Feb 06 '11 at 08:21
  • @korovyansk Pasted my code in the previous comments. Let me know if I'm doing anything wrong in the code. Also could you give me some pointers on handling animation on onClick handler. Sorry, I'm a newbie trying hard! :-) – sammydude Feb 06 '11 at 08:23
  • The problem I'm facing is, both the images are of different resolutions, but still it occupies the entire view area. So, unable to see any animation. – sammydude Feb 06 '11 at 08:24
  • ImageView doesn't handle any click out of the box, so you selector doesn't catch pressed_state and always return default state. Add android:clickable="true" to your ImageView params. – AlexKorovyansky Feb 06 '11 at 08:33
  • @korovyansk Thanks. Added clickable. Still no animation. The image which is supposed to appear when pressed, does appear but takes up the same size as the default image. But it should appear smaller than the default image, – sammydude Feb 06 '11 at 08:46
  • Ok, I've test it. Image changes, but keeps size. We can use such workaround: make both pictures of the same size (image of small picture will be centred in transparent canvas with size of larger picture). It's work for me. – AlexKorovyansky Feb 06 '11 at 09:27
  • This way is good for situation in that small and large image are different. Otherwise smooth animation is more suitable (users prefer animation rather than flickering). You can check this topic http://stackoverflow.com/questions/2270751/android-imageview-onclick-animation if you interest in it. – AlexKorovyansky Feb 06 '11 at 09:34
  • @korovyansk Thank you so much! Will check out the above link too! :-) – sammydude Feb 06 '11 at 09:58
  • Please remove excessive comments. And score answer, if problem is solved. – AlexKorovyansky Feb 06 '11 at 10:55
  • @korovyansk Thanks a ton Korovyansk! The animation tip worked! Thanks for the link. My problem has been resolved. :-) – sammydude Feb 06 '11 at 11:11
  • Both suggestions suggested by Korovyansk worked. So have credited him for the correct answer. Answers provided above. – sammydude Feb 06 '11 at 11:13