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. 运行应用程序,你将看到圆形图像会在不断地扩大和缩小。

相关内容

热门资讯

专业讨论!wepoker透视脚... 专业讨论!wepoker透视脚本下载,德普之星私人局辅助免费,玩家教程(有挂辅助);人气非常高,ai...
一秒答解!hh poker插件... 1、一秒答解!hh poker插件下载,wejoker开挂,存在挂教程(有挂方法)(UU poker...
科技分享!hh poker插件... 科技分享!hh poker插件下载,德普之星辅助器,AI教程(有挂技巧);实战中需综合运用上述技巧,...
2024教程!we-poker... 2024教程!we-poker软件,wepoker私人局俱乐部,2025新版总结(有挂教程)1、不需...
盘点十款!pokemomo辅助... 盘点十款!pokemomo辅助软件,hhpoker为什么一直输,力荐教程(有挂方法)1、点击下载安装...
今日科普!哈糖大菠萝有没有挂,... 今日科普!哈糖大菠萝有没有挂,aapoker破解侠是真的吗,科技教程(有挂神器);小薇(透视辅助)致...
盘点一款!wejoker私人辅... 盘点一款!wejoker私人辅助软件,智星德州插件怎么下载,可靠教程(有挂神器);《WPK辅助透视》...
我来分享!pokemmo手机脚... 我来分享!pokemmo手机脚本,wepoker怎么拿到好牌,线上教程(有挂神器);玩家必备必赢加哟...
实测必看!aapoker怎么设... 实测必看!aapoker怎么设置提高好牌几率,werplan外挂,必胜教程(有挂辅助)准备好在aap...
记者发布!steampoker... 1、记者发布!steampokermaster辅助,cloudpoker怎么开挂,分享教程(有挂透明...