Is there away to show some kind of effect when imageview pressed. I use imageview as a button, so need to show some effect on touch. Many existing threads propose selectors with multiple images. This is too much work, because I have a lot of imageviews. I am also open to extending the imageview class. Any ideas or workaround.
Asked
Active
Viewed 4,647 times
2
-
have you seen `ImageButton` class? – pskink Oct 06 '15 at 04:18
-
http://stackoverflow.com/a/7176006 – Sree Oct 06 '15 at 04:20
-
https://github.com/traex/RippleEffect – karan Oct 06 '15 at 04:21
-
Thanks all. Imagebutton is not good, because I use this on a custom title bar. @saree, u have specified a way where I have to use a selector for each imageview. I like karan sugession. But I was looking for like glow effect or some animation. – pats Oct 06 '15 at 04:28
-
so what that you use this on a custom title bar? – pskink Oct 06 '15 at 04:29
-
Imagebutton is not flat. – pats Oct 06 '15 at 04:32
-
so make a custom `ImageView` and use a selector as a background – pskink Oct 06 '15 at 05:00
-
http://stackoverflow.com/questions/17405272/button-like-click-effect-for-imageview-in-android – IntelliJ Amiya Oct 06 '15 at 05:51
1 Answers
9
In a click function add
ImageView img= (ImageView) view.findViewById(R.id.theID);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);
img.startAnimation(animation);
Create an anim
folder in Assets and then cleate an animation resource file named alpha
inside the file paste the following
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="50"
android:fromAlpha="0.5"
android:toAlpha="1.0" />
This type of animation just sets the Alpha tranparency to 50% and back to 100% so the image will flash.
There are many animations so have a look around on the net to find which one you like and create the anim resource file and put the name here R.anim.alpha);
in your imageView xml file you can add android:onClick="myClickFunction"
and then in the activity add
public void myClickFunction(View v) {
ImageView img = (ImageView) v.findViewById(R.id.theID);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.alpha);
img.startAnimation(animation);
}

Tasos
- 5,321
- 1
- 15
- 26