Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android imageview onClick animation

I guess this is kind of an odd question but I have tried setting onClicklistener on an ImageView and it has worked. But the problem is that the user cannot sense the click. I mean if some of u have worked on other mobile environs(like Apple iPhone) then when we click on an Image in other environs then it gives an effect on the image so that the user can understand that the image has been clicked.

I have tried setting alpha using setalpha method but it doesn't work. Though the same thing is working fine on onFocusListener implementation. Can some1 suggest a different way to modify the image on click...

I am new to android so haven't learnt the nuances of simple animation also... if there is any simple animation I can use for the same then please let me know.

Thanks!

like image 781
JaVadid Avatar asked Feb 16 '10 04:02

JaVadid


People also ask

How can I give an ImageView click effect like a button on Android?

You can do this with a single image using something like this: //get the image view ImageView imageView = (ImageView)findViewById(R. id. ImageView); //set the ontouch listener imageView.

Can ImageView be used as button?

ImageView is used when we want to work with images or we want to display them in our application. So, this article will give you a complete idea of using an ImageView as a Button in android studio. So, without wasting further time let's go to the article and read how we can achieve this task.

How do you make an ImageView clickable like a simple button?

Using clickable images You can turn any View , such as an ImageView , into a button by adding the android:onClick attribute in the XML layout. The image for the ImageView must already be stored in the drawable folder of your project.


1 Answers

   <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android">  <alpha android:fromAlpha = "1.0" android:toAlpha = "0.5" android:duration = "300"> </alpha> <scale android:fromXScale = "1" android:toXScale = "0.9"  android:fromYScale = "1" android:toYScale = "0.9"  android:pivotX="50%" android:pivotY="50%"  android:duration = "50"> </scale> </set> 

I don't know if this is the correct method but defining an animation as mentioned did the trick. Now we just have to give

public void onClick(View v) { v.startAnimation(AnimationUtils.loadAnimation(Context, R.anim.image_click)); //Your other coding if present } 

in the OnClick method and the change will be visible...

like image 143
JaVadid Avatar answered Oct 13 '22 09:10

JaVadid