You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android(Java)如何实现ImageView圆形生长带旋转的展示动画

Android Java实现圆形星星入场动画方案

你需要的效果是三类动画同步执行实现的,只需将圆形揭示、平移、旋转三类动画组合进AnimatorSet同步播放即可,具体实现步骤如下:

1. 布局配置

首先在布局文件中添加星星ImageView,默认设置为不可见:

<ImageView
    android:id="@+id/iv_star"
    android:layout_width="80dp"
    android:layout_height="80dp"
    android:src="@drawable/round_star" <!-- 替换为你的星星图片资源 -->
    android:visibility="invisible"
    <!-- 自行配置最终需要放置的位置约束/布局参数 -->
/>

2. 动画实现代码

在Activity/Fragment中调用以下方法触发动画即可:

private void startStarEnterAnim(ImageView starIv) {
    // 等待View测量完成后获取宽高,避免拿不到尺寸
    starIv.post(() -> {
        int width = starIv.getWidth();
        int height = starIv.getHeight();

        // 1. 创建圆形揭示动画:从右下角为中心点,从0半径扩展到覆盖整个View
        float endRadius = (float) Math.hypot(width, height);
        Animator revealAnim = ViewAnimationUtils.createCircularReveal(
                starIv,
                width, // 中心点X:右下角
                height, // 中心点Y:右下角
                0f,
                endRadius
        );

        // 2. 创建平移动画:从右下角偏移位置移动到最终位置
        // 这里的偏移值可以根据需求调整,示例为从200dp偏移量移入
        float offsetPx = dp2px(starIv.getContext(), 200);
        ObjectAnimator transXAnim = ObjectAnimator.ofFloat(starIv, "translationX", offsetPx, 0f);
        ObjectAnimator transYAnim = ObjectAnimator.ofFloat(starIv, "translationY", offsetPx, 0f);

        // 3. 创建旋转动画:入场时同步旋转360度
        ObjectAnimator rotateAnim = ObjectAnimator.ofFloat(starIv, "rotation", 0f, 360f);

        // 4. 组合所有动画同步播放
        AnimatorSet animSet = new AnimatorSet();
        animSet.playTogether(revealAnim, transXAnim, transYAnim, rotateAnim);
        animSet.setDuration(600); // 动画时长可根据动效节奏调整
        animSet.setInterpolator(new DecelerateInterpolator()); // 减速插值器更符合自然动效
        // 动画开始前设置View可见
        animSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                starIv.setVisibility(View.VISIBLE);
            }
        });
        animSet.start();
    });
}

// dp转px工具方法
private float dp2px(Context context, float dpValue) {
    return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, context.getResources().getDisplayMetrics());
}

兼容说明

createCircularReveal方法为Android 5.0(API 21)及以上系统提供,低于该版本的设备可直接跳过揭示动画,仅执行平移+旋转组合动画即可。


内容的提问来源于stack exchange,提问作者Umair Ahmed

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.07 10:00:03