我希望实现类似的动画:
https://dribbble.com/shots/1767235-Rizon-Location-animation
,并在中间的圆圈中显示图像。
我知道会使用缩放动画,我在圆形图像视图中使用它:
<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toXScale="0.5"
android:toYScale="0.5" />
这会导致图像脉动,但是如何在图像周围显示和动画环,就像上面的动画一样?任何提示都会有所帮助。
谢谢!
答案 0 :(得分:1)
覆盖onDraw方法并为按钮绘制第一个圆,创建一个布尔变量来控制按钮何时开始脉冲,何时不是。最后用alpha作为背景绘制你的第二个圆圈。产生脉动效果:
@Override
protected void onDraw(Canvas canvas) {
int w = getMeasuredWidth();
int h = getMeasuredHeight();
mCirclePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mCirclePaint.setColor(mColor);
mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mBackgroundPaint.setColor(Util.adjustAlpha(mColor, 0.4f));
//Draw circle
canvas.drawCircle(w/2, h/2, MIN_RADIUS_VALUE , mCirclePaint);
if (mAnimationOn) {
if (mRadius >= MAX_RADIUS_VALUE)
mPaintGoBack = true;
else if(mRadius <= MIN_RADIUS_VALUE)
mPaintGoBack = false;
//Draw pulsating shadow
canvas.drawCircle(w / 2, h / 2, mRadius, mBackgroundPaint);
mRadius = mPaintGoBack ? (mRadius - 0.5f) : (mRadius + 0.5f);
invalidate();
}
super.onDraw(canvas);
}
public void animateButton(boolean animate){
if (!animate)
mRadius = MIN_RADIUS_VALUE;
mAnimationOn = animate;
invalidate();
}
希望它会对你有所帮助!