帧动画和补间动画

帧动画

帧动画 类似 照相机,就是播放一系列的图片资源

帧动画使用步骤:

1. 将一系列图片复制到res/drawable中
2.在res/drawable中创建一个animation-list格式的xml文件(例如名为girl),并把帧动画用到的图片加载进来
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false" >
    <item
        android:drawable="@drawable/girl_1"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_2"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_3"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_4"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_5"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_6"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_7"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_8"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_9"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_10"
        android:duration="200"/>
    <item
        android:drawable="@drawable/girl_11"
        android:duration="200"/>
  

</animation-list>
3.控件中添加一个imageview,设置图片资源,启动动画
//找到imageview
		ImageView iv = (ImageView) findViewById(R.id.iv); 
		//设置背景资源
		iv.setBackgroundResource(R.drawable.girl);
		
		//获取动画资源  这句话可能是一个耗时的操作,所以睡眠一段时间再开启动画 
		final AnimationDrawable background = (AnimationDrawable) iv.getBackground();
		
		
		new Thread(){public void run() {
			
			try {
				Thread.sleep(20);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			background.start(); //开启动画
			
			
		};}.start();

补间动画

下面例子代码中的iv是一个imageview控件

AlphaAnimation---透明度动画

  /**
	 * 透明度变化的动画
	 * @param view
	 */
	public void alpha(View view) {
		AlphaAnimation aa = new AlphaAnimation(0, 1.0f);
		//动画播放的时间
		aa.setDuration(2000);
		//重复次数
		aa.setRepeatCount(2);
		//设置重复的模式
		aa.setRepeatMode(Animation.REVERSE);
		iv.startAnimation(aa);
	}

RotateAnimation---旋转动画

/**
	 * 旋转变化的动画
	 * @param view
	 */
	public void rotate(View view) {
		//旋转度数,旋转相对点
		RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		//动画播放的时间
		ra.setDuration(2000);
				//重复次数
		ra.setRepeatCount(2);
		ra.setRepeatMode(Animation.REVERSE);
		iv.startAnimation(ra);
	}

TranslateAnimation---位移动画

/**
	 * 位移变化的动画
	 * @param view
	 */
	public void trans(View view) {
		TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.5f, Animation.RELATIVE_TO_PARENT, 0.5f, 
				Animation.RELATIVE_TO_PARENT, -0.5f, Animation.RELATIVE_TO_PARENT, 0.5f);
		ta.setDuration(2000);
		//重复次数
		ta.setRepeatCount(2);
		ta.setRepeatMode(Animation.REVERSE);
		iv.startAnimation(ta);
		
	}

ScaleAnimation---缩放动画

	/**
	 * 缩放变化的动画
	 * @param view
	 */
	public void scale(View view) {
		ScaleAnimation sa = new ScaleAnimation(0.1f, 2.0f, 0.1f, 2.0f, 
				Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
		sa.setDuration(2000);
		//重复次数
		sa.setRepeatCount(2);
		sa.setRepeatMode(Animation.REVERSE);
		sa.setFillAfter(true);//设置填充after的效果
		iv.startAnimation(sa);
	}

AnimationSet---动画合集

上面的动画都可以加入到动画合集中,然后启动动画合集,合集中的动画效果会一起显示
	/**
	 * 动画集合
	 * @param view
	 */
	public void set(View view){
		//动画插入器
		AnimationSet set = new AnimationSet(false);
		RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
		//动画播放的时间
		ra.setDuration(2000);
				//重复次数
		ra.setRepeatCount(2);
		ra.setRepeatMode(Animation.REVERSE);
		TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, -0.3f, Animation.RELATIVE_TO_PARENT, 0.3f, 
				Animation.RELATIVE_TO_PARENT, -0.3f, Animation.RELATIVE_TO_PARENT, 0.3f);
		ta.setDuration(2000);
		//重复次数
		ta.setRepeatCount(2);
		ta.setRepeatMode(Animation.REVERSE);
		ScaleAnimation sa = new ScaleAnimation(0.1f, 2.0f, 0.1f, 2.0f, 
				Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f);
		sa.setDuration(2000);
		//重复次数
		sa.setRepeatCount(2);
		sa.setRepeatMode(Animation.REVERSE);
		set.addAnimation(ra);
		set.addAnimation(sa);
		set.addAnimation(ta);
		iv.startAnimation(set);
	}

使用xml文件设置补间动画效果

1.在res目录下创建一个目录用来存放定义动画效果的xml文件
2.在代码中引用xml文件,并开启动画

引用xml文件代码

package com.itheima.bujiananim;

import android.R.animator;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

public class MainActivity extends Activity {

	private ImageView iv;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		//作用 就是用来显示动画效果
		iv = (ImageView) findViewById(R.id.iv);
		
	}


	/**
	 * 透明动画
	 * @param v
	 */
	public void alpha(View v){
		//1.0 意味完全不透明       0.0 完全透明 
		Animation aa = AnimationUtils.loadAnimation(this, R.anim.alpha);
		//开启动画 
		iv.startAnimation(aa); 
		
		
		
	}
	
	
	/**
	 *  缩放动画
	 * @param v
	 */
	public void scale(View v){
		//Animation.RELATIVE_TO_SELF 相对于自己进行缩放
		Animation sa = AnimationUtils.loadAnimation(this, R.anim.scale);
		
		//开启动画 
		iv.startAnimation(sa); 
		
	}
	
	/**
	 *  位移动画
	 * @param v
	 */
	public void trans(View v){
		
		Animation ta = AnimationUtils.loadAnimation(this, R.anim.translate);
		
		//开启动画 
		iv.startAnimation(ta); 
		
	}
	
	
	/**
	 *  位移动画
	 * @param v
	 */
	public void rotate(View v){
//		
		Animation ra = AnimationUtils.loadAnimation(this, R.anim.rotate);
		iv.startAnimation(ra);
		
		
	}
	
	public void animset(View v){
		
	    Animation set = AnimationUtils.loadAnimation(this, R.anim.set);
		//把动画设置给 iv 
		iv.startAnimation(set);
		
		
	}
	
	
	

}

透明动画xml定义代码

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromAlpha="0"
    android:repeatCount="2"
    android:repeatMode="reverse"
    android:toAlpha="1.0" >

</alpha>

旋转动画xml定义代码

<?xml version="1.0" encoding="utf-8"?>
<rotate
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"

    android:duration="2000"
    android:repeatCount="2"
    android:repeatMode="reverse"    
    xmlns:android="http://schemas.android.com/apk/res/android">
    

</rotate>

缩放动画xml定义代码

<?xml version="1.0" encoding="utf-8"?>
<scale
    android:fromXScale="0.1"
    android:toXScale="2.0"
    android:fromYScale="0.1"
    android:toYScale="2.0"
    android:duration="2000"
    android:repeatCount="2"
    android:repeatMode="reverse"
    android:pivotX="50%"
    android:pivotY="50%"
    xmlns:android="http://schemas.android.com/apk/res/android">
    

</scale>

平移动画xml定义代码

<?xml version="1.0" encoding="utf-8"?>
<translate
    android:fromXDelta="-50%p"
    android:toXDelta="50%p"
    android:fromYDelta="-50%p"
    android:toYDelta="50%p"

    android:duration="2000"
    android:repeatCount="2"
    android:repeatMode="reverse"    
    xmlns:android="http://schemas.android.com/apk/res/android">
    

</translate>

动画集合xml定义代码

<?xml version="1.0" encoding="utf-8"?>
<set>
    <alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2000"
    android:fromAlpha="0"
    android:repeatCount="2"
    android:repeatMode="reverse"
    android:toAlpha="1.0" >

</alpha>

    <scale
    android:fromXScale="0.1"
    android:toXScale="2.0"
    android:fromYScale="0.1"
    android:toYScale="2.0"
    android:duration="2000"
    android:repeatCount="2"
    android:repeatMode="reverse"
    android:pivotX="50%"
    android:pivotY="50%"
    xmlns:android="http://schemas.android.com/apk/res/android">
    
</scale>
    

</set>








Stkcd [股票代码] ShortName [股票简称] Accper [统计截止日期] Typrep [报表类型编码] Indcd [行业代码] Indnme [行业名称] Source [公告来源] F060101B [净利润现金净含量] F060101C [净利润现金净含量TTM] F060201B [营业收入现金含量] F060201C [营业收入现金含量TTM] F060301B [营业收入现金净含量] F060301C [营业收入现金净含量TTM] F060401B [营业利润现金净含量] F060401C [营业利润现金净含量TTM] F060901B [筹资活动债权人现金净流量] F060901C [筹资活动债权人现金净流量TTM] F061001B [筹资活动股东现金净流量] F061001C [筹资活动股东现金净流量TTM] F061201B [折旧摊销] F061201C [折旧摊销TTM] F061301B [公司现金流1] F061302B [公司现金流2] F061301C [公司现金流TTM1] F061302C [公司现金流TTM2] F061401B [股权现金流1] F061402B [股权现金流2] F061401C [股权现金流TTM1] F061402C [股权现金流TTM2] F061501B [公司自由现金流(原有)] F061601B [股权自由现金流(原有)] F061701B [全部现金回收率] F061801B [营运指数] F061901B [资本支出与折旧摊销比] F062001B [现金适合比率] F062101B [现金再投资比率] F062201B [现金满足投资比率] F062301B [股权自由现金流] F062401B [企业自由现金流] Indcd1 [行业代码1] Indnme1 [行业名称1] 季度数据,所有沪深北上市公司的 分别包含excel、dta数据文件格式及其说明,便于不同软件工具对数据的分析应用 数据来源:基于上市公司年报及公告数据整理,或相关证券交易所、各部委、省、市数据 数据范围:基于沪深北证上市公司 A股(主板、小企业板、创业板、科创板等)数据整理计算
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Barry__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值