Cas*_*ash 8 animation android drawable
我正在为徽标添加发光动画效果.到目前为止,我已经设法使用LayeredDrawable获取徽标背后的发光图像,但我无法弄清楚如何为它制作动画.我发现AlphaAnimation会达到预期的效果,但不幸的是我只能将它应用于Views,而不是Drawables.我怎样才能达到这个效果?
简单的例子
final ImageView imageView = (ImageView) findViewById(R.id.animatedImage);
final Button animated = (Button) findViewById(R.id.animated);
animated.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Drawable drawable = imageView.getDrawable();
if (drawable.getAlpha() == 0) {
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 255));
animator.setTarget(drawable);
animator.setDuration(2000);
animator.start();
} else {
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(drawable, PropertyValuesHolder.ofInt("alpha", 0));
animator.setTarget(drawable);
animator.setDuration(2000);
animator.start();
}
}
});
Run Code Online (Sandbox Code Playgroud)
方法getAlpha()添加api 19.但这不是一个很大的限制,你可以将状态保存在局部变量中.ObjectAnimator添加Android 3.0(api 11),也许旧版Android你可以使用nineoldandroids.我没有用九角龙测试.
| 归档时间: |
|
| 查看次数: |
11738 次 |
| 最近记录: |