Android课程设计第三天帧动画区间动画

 注意:课程设计只为完成任务,不做细节描述~

 点火是帧动画,发射是区间动画,于是

复制代码
 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     tools:context=".MainActivity"
 7     android:background="@mipmap/bg">
 8     <ImageView
 9         android:id="@+id/img_rocekt"
10         android:layout_width="30dp"
11         android:layout_height="90dp"
12         android:background="@drawable/fire"
13         android:layout_alignParentBottom="true"
14         />
15     <Button
16         android:id="@+id/btn_launch"
17         android:layout_width="60dp"
18         android:layout_height="30dp"
19         android:text="发射"
20         android:background="#0ccfff"
21         android:layout_alignParentBottom="true"
22         android:layout_alignParentRight="true"
23         android:layout_margin="15dp"
24         android:textSize="12sp"
25         />
26     <Button
27         android:layout_width="60dp"
28         android:layout_height="30dp"
29         android:text="点火"
30         android:id="@+id/btn_fire"
31         android:background="#0ccfff"
32         android:textSize="12sp"
33         android:layout_toLeftOf="@id/btn_launch"
34         android:layout_alignBottom="@id/btn_launch"
35         />
36 </RelativeLayout >
复制代码
复制代码
 1 package com.example.myapplication2;
 2 
 3 import android.graphics.drawable.AnimationDrawable;
 4 import android.support.v7.app.AppCompatActivity;
 5 import android.os.Bundle;
 6 import android.view.View;
 7 import android.view.animation.Animation;
 8 import android.view.animation.AnimationUtils;
 9 import android.widget.Button;
10 import android.widget.ImageView;
11 /*
12 安卓基本动画
13 帧动画
14            连贯的图片按照顺序播放
15            布局文件中准备一个控件,用来承载动画的
16            准备动画文件background属性里<animation-list>
17            在java代码中,声明实例化控件
18            声明并初始化动画对象 AnimationDrawable
19            启动动画 动画对象直接启动
20 区间动画 透明度 旋转 缩放 位移
21             在布局文件中准备一个控件,用来承载动画
22             准备动画文件
23             在java代码中,声明实例化控件
24             声明并初始化动画对象 Animation
25             启动动画 执行者启动动画对象
26 属性动画 模拟
27  */
28 public class MainActivity extends AppCompatActivity {
29 
30     private View img_rocket;
31     //声明一个帧数动画的类的对象
32     private AnimationDrawable anim_fire;
33     private  Button btn_launch;
34     //区间动画的动画类对象
35     private  Animation anim_launch=null;
36     @Override
37     protected void onCreate(Bundle savedInstanceState) {
38         super.onCreate(savedInstanceState);
39         setContentView(R.layout.activity_main);
40         img_rocket=findViewById(R.id.img_rocekt);
41         anim_fire= (AnimationDrawable) img_rocket.getBackground();
42         anim_fire.start();
43 
44         btn_launch= (Button) findViewById(R.id.btn_launch);
45 
46         btn_launch.setOnClickListener(new View.OnClickListener(){
47             @Override
48             public void onClick(View v) {
49                     anim_launch=AnimationUtils.loadAnimation(MainActivity.this,R.anim.launch);
50                     img_rocket.startAnimation(anim_launch);
51             }
52         });
53 
54     }
55 
56 
57 }
复制代码
复制代码
1 <?xml version="1.0" encoding="utf-8"?>
2 <translate xmlns:android="http://schemas.android.com/apk/res/android"
3     android:fromXDelta="0"
4     android:toXDelta="0"
5 
6     android:fromYDelta="0"
7     android:toYDelta="-80%p"
8     android:duration="4000">
9 </translate>
复制代码
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <item android:drawable="@mipmap/rocket_launch_1" android:duration="200"></item>
    <item android:drawable="@mipmap/rocket_launch_2" android:duration="200"></item>

</animation-list>

 

posted @   樱花落舞  阅读(387)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示