2012-06-21 78 views
6

我正在申请一个应用程序,在我的主页我需要给一个标志(imageview)发光和褪色效果动画我试了很多,找不到如何给发光效果动画我知道发光效果的onclick事件,请帮助我解决这个问题 预先感谢android动画发光效果对imageview

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; 
} 
} 

这个代码是用于触摸事件,我想动画

+0

眨眼型动画对吗?你需要 – Khan

+0

@come在http://chat.stackoverflow.com/rooms/11936/android-lite – Khan

+0

谢谢@Khan我找到了答案 –

回答

2

其简单

制作2套图像之一是轻的和另一个一会阳光明媚(明亮)

然后,您可以使用AlphaAnimation动画图像。

+0

请给我一些示例代码谢谢你的时间 –

18

辉光效果核查Glow effect

是眨眼类型的动画使用它的工作原理,你必须改变Reapeatcount和持续时间accroding您的要求

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); 

使用后下方

给出
imageview.startAnimation(blinkanimation); or imageview.setAnimation(blinkanimation); 
+0

我想发光效果不闪烁效果请帮助我 –

+0

@ThiruVT我编辑了我的答案检查它 – Khan

+0

它是为触摸事件在该网格视图我想动画任何方式谢谢 –