Android_Butterfly_动画

Android_Butterfly_动画

运行效果
请添加图片描述
请添加图片描述
所需文件
请添加图片描述
请添加图片描述

MainActivity

package com.example.a517_butter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
//import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;import androidx.appcompat.app.AppCompatActivity;public class MainActivity extends AppCompatActivity {private int screenWidth;private ImageView iv_butterfly,iv_bird;private AnimationDrawable animation;private AnimatorSet flyAnimatorSet;private ObjectAnimator objectAnimator;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);init();}private void init(){getWindowWidth();iv_butterfly=findViewById(R.id.iv_butterfly);iv_bird=findViewById(R.id.iv_bird);flyAnimation(1); //实现蝴蝶飞舞的效果flyAnimation(2); //实现小鸟飞舞的效果}/*** 获取屏幕宽度*/private void getWindowWidth(){DisplayMetrics dm=new DisplayMetrics();getWindowManager().getDefaultDisplay().getMetrics(dm);screenWidth= dm.widthPixels;}/*** 实现飞舞的效果*/private void flyAnimation(int flag){flyAnimatorSet=new AnimatorSet();if (flag==1) {//获取逐帧动画animation= (AnimationDrawable) iv_butterfly.getBackground();//设置蝴蝶在水平方向移动的距离为屏幕的宽度-270objectAnimator = ObjectAnimator.ofFloat(iv_butterfly,"translationX", screenWidth - 270);objectAnimator.setDuration(3*1000);//设置动画时间为3秒}else if (flag==2){//获取逐帧动画animation= (AnimationDrawable) iv_bird.getBackground();//设置小鸟在水平方向移动的距离为屏幕的宽度objectAnimator = ObjectAnimator.ofFloat(iv_bird,"translationX", screenWidth);objectAnimator.setRepeatCount(Animation.RESTART); //重新开始播放动画objectAnimator.setRepeatCount(Animation.INFINITE);//循环播放动画objectAnimator.setDuration(10*1000);//设置动画时间为10秒}objectAnimator.setInterpolator(new LinearInterpolator());//设置线性插值器flyAnimatorSet.play(objectAnimator);animation.start();     //开启逐帧动画flyAnimatorSet.start();//开启属性动画}
}

activity_main

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/bg"><ImageViewandroid:id="@+id/iv_bird"android:layout_width="120dp"android:layout_height="120dp"android:layout_marginTop="20dp"android:background="@drawable/bird_animation" /><ImageViewandroid:layout_marginBottom="100dp"android:layout_alignParentBottom="true"android:id="@+id/iv_butterfly"android:layout_width="120dp"android:layout_height="120dp"android:layout_marginTop="20dp"android:background="@drawable/butterfly_animation" />
</RelativeLayout>

bird_animation

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" ><item android:drawable="@drawable/bird_one" android:duration="100"/><item android:drawable="@drawable/bird_two" android:duration="100"/><item android:drawable="@drawable/bird_three" android:duration="100"/><item android:drawable="@drawable/bird_four" android:duration="100"/><item android:drawable="@drawable/bird_five" android:duration="100"/><item android:drawable="@drawable/bird_six" android:duration="100"/><item android:drawable="@drawable/bird_seven" android:duration="100"/><item android:drawable="@drawable/bird_eight" android:duration="100"/>
</animation-list>

butterfly_animation

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" ><item android:drawable="@drawable/butterfly_one" android:duration="100"/><item android:drawable="@drawable/butterfly_two" android:duration="100"/><item android:drawable="@drawable/butterfly_three" android:duration="100"/><item android:drawable="@drawable/butterfly_four" android:duration="100"/><item android:drawable="@drawable/butterfly_five" android:duration="100"/><item android:drawable="@drawable/butterfly_six" android:duration="100"/><item android:drawable="@drawable/butterfly_seven" android:duration="100"/><item android:drawable="@drawable/butterfly_eight" android:duration="100"/>
</animation-list>

图片素材
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://xiahunao.cn/news/1381463.html

如若内容造成侵权/违法违规/事实不符,请联系瞎胡闹网进行投诉反馈,一经查实,立即删除!

相关文章

matlab 绘花,MATLAB绘图花样一

多组数据在一张图中显示----hold on x = [5 20 40 60 80 100 120]; y = [-0.2 -0.36 -0.26 -0.24 -0.33 -0.41 -0.55]; y1 = [-0.15 -0.31 -0.21 -0.19 -0.28 -0.36 -0.5]; y2 = [-0.25 -0.41 -0.31 -0.29 -0.38 -0.46 -0.6]; plot(x,y); hold on; plot(x,y1); hold on; plot(x…

R语言笔记(一)

1.iris&#xff1a;鸢尾花数据集 Sepal&#xff1a;花萼 Petal&#xff1a;花瓣 Species&#xff1a;种数 2.sunflowerplot(iris[,4:5],col”gold”,seg.col”gold”) 表示画出向日葵的散点图&#xff0c;iris[,4:5]表示iris数据的第四、五列的数据画向日葵散点图…

python用turtle画太阳花_Python绘图——认识turtle小海龟

海龟作图&#xff0c;turtle是Python重要的标准库之一&#xff0c;我们可以编写指令让一个虚拟的小海龟在屏幕上来回移动。这个海龟带着一只钢笔&#xff08;pen&#xff09;&#xff0c;我们可以让海龟无论移动到哪都使用这只钢笔来绘制线条。 海龟作图最初源自20世纪60年代的…

向日葵android平板,向日葵远程控制 - 黑科技改变生活,让端游一秒变手游 - Android 应用 - iPad - 【最美应用】...

玩主机的看不起玩平台的&#xff0c;玩平台的看不起玩端游的&#xff0c;玩端游的看不起玩页游的&#xff0c;玩页游的还看不起玩手游的。 现在不要分什么彼此了&#xff0c;通过以下方法&#xff0c;想用手机玩平台游戏、玩端游、玩页游&#xff0c;可一次实现&#xff01; 手…

海龟画图 python太阳花_python画图之“小海龟”turtle

“小海龟”turtle是Python语言中一个很流行的绘制图像的函数库&#xff0c;想象一个小乌龟&#xff0c;在一个横轴为x、纵轴为y的坐标系原点&#xff0c;(0,0)位置开始&#xff0c;它根据一组函数指令的控制&#xff0c;在这个平面坐标系中移动&#xff0c;从而在它爬行的路径上…

python turtle库制作可爱的假向日葵

效果图&#xff1a; 是不是很可爱呢&#xff01;现在就带各位朋友们亲手做一个假向日葵花吧 # sun flower 向日葵 # 创作人&#xff1a;李国庆 # 扣扣&#xff1a;1974914843 import turtle as tt.begin_fill() t.pendown() t.circle(60) t.fd(14) t.fillcolor(yellow) t.end…

windows系统链接UBuntu向日葵

参考链接&#xff1a; 1、https://www.pianshen.com/article/67791913548/ 2、https://www.codeleading.com/article/8793979874/ 3、https://www.linuxidc.com/Linux/2011-07/39491.htm 解决方法 1.官网下载: https://sunlogin.oray.com/download/ 双击deb安装&#xff0c;然…

python画行向日葵,基于matplotlib的向日葵散点图

我不知道有什么matplotlib实现&#xff0c;但不难做到。在这里&#xff0c;我让hexbin进行计数&#xff0c;然后遍历每个单元格并添加适当数量的花瓣&#xff1a; import numpy as np import matplotlib.pyplot as plt from matplotlib import colors np.random.seed(0) n 200…

python用turtle画太阳花_详解python使用turtle库来画一朵花

看了群主最后成像的图片&#xff0c;应该是循环了36次画方框&#xff0c;每次有10度的偏移。 当然不能提前看答案&#xff0c;自己试着写代码。 之前有用过海龟画图来画过五角星、奥运五环、围棋盘等&#xff0c;所以感觉不难。 # !/usr/bin/env python # -*- coding:utf-8…

微信小程序隐私协议模板

在 设置 中找到 用户隐私保护 进行更新&#xff0c;如下图&#xff1a; 具体协议补充可参考如下&#xff1a; 为了分辨用户&#xff0c;开发者将在获取你的明示同意后&#xff0c;收集你的微信昵称、头像 为了显示距离&#xff0c;开发者将在获取你的明示同意后&#xff0c;收…

多线程与并发编程面试题总结

多线程与并发编程 多线程 线程和进程的区别&#xff1f; 从操作系统层面上来讲&#xff1a;进程(process)在计算机里有单独的地址空间&#xff0c;而线程只有单独的堆栈和局部内存空间&#xff0c;线程之间是共享地址空间的&#xff0c;正是由于这个特性&#xff0c;对于同…

linux鲁班猫代码初尝试[编译镜像][修改根文件系统重编译][修改设备树改屏幕为MIPI]

编译镜像 官方百度云盘资料:https://doc.embedfire.com/linux/rk356x/quick_start/zh/latest/quick_start/baidu_cloud/baidu_cloud.html 解压虚拟机压缩包:"鲁班猫\8-SDK源码压缩包\开发环境虚拟机镜像\ubuntu20.04.7z"后既可以用VMware打开,打开后可以看到已经有…

idea 快捷键代码行标记并快捷跳到标记行(搬砖必备)

idea有一个组合快捷键 非常好用 快捷键1 标记代码行&#xff08;左边的行数会出现一个1&#xff0c;代表着已经标记了&#xff09;&#xff1a; ctrlshift1 快捷键2 迅速跳到标记行&#xff08;直接抵达砖厂&#xff0c;哈哈&#xff09;&#xff1a; ctrl1 这边给大家送上…

圈子才是成功的捷径

前言 最近我在读徐涛写的《历史的面孔》这本书&#xff0c;感受颇深&#xff0c;启发挺大的。 真心建议大家可以读一读历史人物相关的书籍&#xff0c;每个历史人物在其所在的背景下&#xff0c;每一个的抉择几乎都能给人以思考。 &#xff08;文末有彩蛋&#xff09; 尤其…

工作中,我们应该走捷径吗?

很多人喜欢走捷径&#xff0c;遇到困难&#xff0c;为了走捷径&#xff0c;找了很多方法&#xff0c;做了很多努力&#xff0c;到最后才发现&#xff0c;这个硬碰硬的过程是避免不了的&#xff0c;除了正面击溃困难&#xff0c;别无选择。 工作中有没有捷径可以走呢&#xff1f…

【几个python虚拟环境会遇到的问题】

几个python虚拟环境会遇到的问题 twine is not recognized as an internal or external command,operable program or batch file.setup命令不报错但不起作用pipreqs is not recognized as an internal or external command,operable program or batch file. ‘twine’ is not …

包管理工具详解npm 、 yarn 、 cnpm 、 npx 、 pnpm(2023)

1、包管理工具npm &#xff08;1&#xff09;包管理工具npm&#xff1a; Node Package Manager&#xff0c;也就是Node包管理器&#xff1b;但是目前已经不仅仅是Node包管理器了&#xff0c;在前端项目中我们也在使用它来管理依赖的包&#xff1b;比如vue、vue-router、vuex、…

OOAD 2 UML

什么是UML&#xff08;Unified Modeling Language&#xff09; 统一建模语言&#xff08;UML&#xff09; 是描述、构造和文档化系统制品的可视化语言。 The Unified Modeling Language is a visual language for specifying,constructing and documenting the artifacts of sy…

北邮:OOAD笔记

1.用例图&#xff1a;描述角色以及角色与用例之间的连接关系 2.类图&#xff1a;描述系统中的类&#xff0c;以及对象&#xff0c;接口&#xff0c;协作等事物之间的关系 3.交互图&#xff1a;描述对象间如何协作&#xff0c;包括序列图和协作图 4.状态图 描述类的对象所有可能…

OOAD实验

类图综述该类图总共分为大致几个模块&#xff1a;用户、票务管理、个人信息管理、用户管理。其中用户分为乘客、票务管理员和系统管理员三类。票务管理员除了负责平时更新车票信息之外&#xff0c;还可以查看车票的销售情况&#xff1b;而系统管理员主要是对乘客和票务管理员的…