zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    MySQL GTID复制Slave跳过错误事务Id以及复制排错问题总结
    Git基础命令整理
    原创-公司项目部署交付环境预检查shell脚本
    解决SecureCRT超时自动断开的问题
    Linux设置显示中文和设置字体
    高等代数4 线性方程组
    高等代数3 行列式
    高等代数2 向量组
    高等代数1 矩阵
    离散数学4 组合数学
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7077757.html
Copyright © 2011-2022 走看看