android动画在imageview上发光效果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11131576/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android animation glow effect on imageview
提问by Thiru VT
I am working on a application, where in my home page i need to give glowing and fading effect animation to a logo (imageview) i tried a lot and could not find how to give glow effect animation and i know glow effect for onclick event please help me with this issue Thanks in advance
我正在开发一个应用程序,在我的主页中,我需要为徽标(imageview)提供发光和褪色效果动画我尝试了很多但找不到如何提供发光效果动画我知道 onclick 事件的发光效果请帮我解决这个问题 提前致谢
public class CustomView extends ImageView{
public CustomView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomView(Context context) {
super(context);
}
boolean drawGlow = false;
//this is the pixel coordinates of the screen
float glowX = 0;
float glowY = 0;
//this is the radius of the circle we are drawing
float radius = 20;
//this is the paint object which specifies the color and alpha level
//of the circle we draw
Paint paint = new Paint();
{
paint.setAntiAlias(true);
paint.setColor(Color.WHITE);
paint.setAlpha(50);
};
@Override
public void draw(Canvas canvas){
super.draw(canvas);
if(drawGlow)
canvas.drawCircle(glowX, glowY, radius, paint);
}
@Override
public boolean onTouchEvent(MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN){
drawGlow = true;
}else if(event.getAction() == MotionEvent.ACTION_UP)
drawGlow = false;
glowX = event.getX();
glowY = event.getY();
this.invalidate();
return true;
}
}
this code is for touch event i want animation
此代码用于触摸事件我想要动画
回答by Khan
For Glow effect check Glow effectand for
对于辉光效果检查辉光效果和
For blink type of animation use this it works you have to change Reapeatcount and Duration accroding to your requirement
对于眨眼类型的动画使用此方法,您必须根据您的要求更改 Reapeatcount 和 Duration
AlphaAnimation blinkanimation= new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
blinkanimation.setDuration(300); // duration - half a second
blinkanimation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
blinkanimation.setRepeatCount(3); // Repeat animation infinitely
blinkanimation.setRepeatMode(Animation.REVERSE);
after use as given below
使用后如下所示
imageview.startAnimation(blinkanimation); or imageview.setAnimation(blinkanimation);
回答by Vipul Shah
Its simple
这很简单
Make 2 sets of images one is light and another one will be sunny(Bright)
制作 2 组图像,一组是浅色,另一组是晴天(明亮)
Then you can use an AlphaAnimation to animate the image.
然后您可以使用 AlphaAnimation 为图像设置动画。