动画实现波纹效果(常规)

动画实现
思路分析:通过动画实现,imageView不停做动画缩放+渐变
最中心的imageView保持不变
中间一层imageView从原始放大到1.4倍,同时从不透明变为半透明
最外层的imageView从1.4倍放大到1.8倍,同时从半透明变为全透明
利用shape画一个圆,作为动画基础视图


<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="65dp"/>
    <solid android:color="@color/colorAccent"/>
shape>

布局视图

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <ImageView
        android:id="@+id/iv_wave"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_gravity="center"
        android:background="@drawable/shape_circle" />
    
    <ImageView
        android:id="@+id/iv_wave_1"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_gravity="center"
        android:background="@drawable/shape_circle" />
    
    <ImageView
        android:id="@+id/iv_wave_2"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_gravity="center"
        android:background="@drawable/shape_circle" />
FrameLayout>
中间imageView的动画

private void setAnim1() {
    AnimationSet as = new AnimationSet(true);
    //缩放动画,以中心从原始放大到1.4倍
    ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 1.4f, 1.0f, 1.4f,
            ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
            ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
    //渐变动画
    AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f);
    scaleAnimation.setDuration(800);
    scaleAnimation.setRepeatCount(Animation.INFINITE);
    alphaAnimation.setRepeatCount(Animation.INFINITE);
    as.setDuration(800);
    as.addAnimation(scaleAnimation);
    as.addAnimation(alphaAnimation);
    iv1.startAnimation(as);
}
最外层imageView的动画

private void setAnim2() {
    AnimationSet as = new AnimationSet(true);
    //缩放动画,以中心从1.4倍放大到1.8倍
    ScaleAnimation scaleAnimation = new ScaleAnimation(1.4f, 1.8f, 1.4f, 1.8f,
            ScaleAnimation.RELATIVE_TO_SELF, 0.5f,
            ScaleAnimation.RELATIVE_TO_SELF, 0.5f);
    //渐变动画
    AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 0.1f);
    scaleAnimation.setDuration(800);
    scaleAnimation.setRepeatCount(Animation.INFINITE);
    alphaAnimation.setRepeatCount(Animation.INFINITE);
    as.setDuration(800);
    as.addAnimation(scaleAnimation);
    as.addAnimation(alphaAnimation);
    iv2.startAnimation(as);
}

转载自
点击这里

你可能感兴趣的:(Android)