Android Studio:扩大和缩小的圆形动画
创始人
2024-08-18 19:30:15
0

在Android Studio中可以使用属性动画来实现扩大和缩小的圆形动画。以下是一个简单的示例代码:

  1. 首先,在XML布局文件中,添加一个ImageView用于显示圆形图像:

  1. 在Java代码中,使用属性动画来创建扩大和缩小的动画效果:
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {
    private ImageView circleImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        circleImageView = findViewById(R.id.circleImageView);

        // 创建扩大动画
        ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(circleImageView, "scaleX", 1.0f, 1.5f);
        scaleXAnimator.setDuration(1000);
        scaleXAnimator.setRepeatMode(ObjectAnimator.REVERSE);
        scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);

        ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(circleImageView, "scaleY", 1.0f, 1.5f);
        scaleYAnimator.setDuration(1000);
        scaleYAnimator.setRepeatMode(ObjectAnimator.REVERSE);
        scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);

        // 创建缩小动画
        ObjectAnimator scaleXAnimator2 = ObjectAnimator.ofFloat(circleImageView, "scaleX", 1.5f, 1.0f);
        scaleXAnimator2.setDuration(1000);
        scaleXAnimator2.setRepeatMode(ObjectAnimator.REVERSE);
        scaleXAnimator2.setRepeatCount(ObjectAnimator.INFINITE);

        ObjectAnimator scaleYAnimator2 = ObjectAnimator.ofFloat(circleImageView, "scaleY", 1.5f, 1.0f);
        scaleYAnimator2.setDuration(1000);
        scaleYAnimator2.setRepeatMode(ObjectAnimator.REVERSE);
        scaleYAnimator2.setRepeatCount(ObjectAnimator.INFINITE);

        // 创建动画集合
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(scaleXAnimator).with(scaleYAnimator);
        animatorSet.play(scaleXAnimator2).with(scaleYAnimator2).after(scaleXAnimator);

        // 设置插值器
        animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());

        // 开始动画
        animatorSet.start();
    }
}
  1. 运行应用程序,你将看到圆形图像会在不断地扩大和缩小。

相关内容

热门资讯

透视玄学!约局吧透视挂下载,约... 透视玄学!约局吧透视挂下载,约局吧辅助器(原来真的有挂);小薇(透视辅助)致您一封信;亲爱约局吧透视...
透视ai代打!aapoker ... 透视ai代打!aapoker ai插件(透视)万能辅助器(切实真的是有挂)透视ai代打!aapoke...
透视系统!拱趴大菠萝机器人,哈... 透视系统!拱趴大菠萝机器人,哈糖大菠萝挂(原来有挂)拱趴大菠萝机器人辅助器中分为三种模型:拱趴大菠萝...
透视脚本!aa poker辅助... 透视脚本!aa poker辅助(透视)透视脚本下载(本来是真的有挂)1、下载好aa poker辅助辅...
辅助透视!xpoker辅助器,... 辅助透视!xpoker辅助器,werplan外卦神器(竟然真的有挂)werplan外卦神器是一种具有...
透视数据!aapoker透视怎... 透视数据!aapoker透视怎么用(透视)免费透视脚本(一贯真的是有挂)1、aapoker透视怎么用...
透视辅助!约局吧能不能开挂,f... 透视辅助!约局吧能不能开挂,fishpoker透视(真是真的有挂)1、下载好约局吧能不能开挂辅助软件...
透视透视挂!aapoker辅助... 透视透视挂!aapoker辅助插件工具(透视)透视脚本下载(总是真的是有挂)1、aapoker辅助插...
透视安装!哈糖大菠萝怎么开挂,... 透视安装!哈糖大菠萝怎么开挂,约局吧德州真的有透视挂吗(一贯有挂)1、每一步都需要思考,不同水平的挑...
透视玄学!来玩德州破解器,xp... 透视玄学!来玩德州破解器,xpoker辅助怎么用(其实真的有挂)来玩德州破解器是一种具有地方特色的麻...