动画的简单讲解之逐帧动画

动画分为逐帧动画、补间动画和属性动画

逐帧动画是依次显示一系列的静态图片,利用人眼的视觉暂留达到动画的效果,

实现方式一:

在资源Drawable中添加animation-listxml动画资源在设置控件背景

<?xml version="1.0" encoding="utf-8"?>

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true" ><!-- oneshot="true"设置不循环播放,若为fals则循环播放 -->

   <item android:drawable="@drawable/ic_launcher" android:duration="1000" />//显示的图片及显示时间。

    <item android:drawable="@drawable/ic_launcher" android:duration="500" />

</animation-list>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical" >

    <ImageView 

        android:layout_width="300dp"

    android:layout_height="300dp"

    android:background="@drawable/lis"/>

 

</LinearLayout>

创建AnimationDrawable对象,获取对象后还可以继续调用addFrame(Drawable frame,int duration);添加图图片,然后必须调用AnimationDrawablestart()方法开始动画或stop()方法停止播放动画。

package com.example.donghua.test;

public class ShowDonghua extends Activity{

ImageView showD;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_donghua);

showD=(ImageView) findViewById(R.id.showD);

AnimationDrawable d=(AnimationDrawable) showD.getBackground();

d.start();

}

}

 

实现方式二:直接new AnimationDrawable对象,添加图片,设置背景,开始动画。

package com.example.donghua.test;

import com.example.sharecontent.R;

import android.annotation.SuppressLint;

import android.app.Activity;

import android.graphics.drawable.AnimationDrawable;

import android.os.Bundle;

import android.widget.ImageView;

 

public class ShowDonghua extends Activity{

ImageView showD;

@SuppressLint("NewApi")

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_donghua);

showD=(ImageView) findViewById(R.id.showD);

//AnimationDrawable d=(AnimationDrawable) showD.getBackground();

//d.start();

AnimationDrawable d=new AnimationDrawable();

d.addFrame(getResources().getDrawable(R.drawable.time_0), 2000);

d.addFrame(getResources().getDrawable(R.drawable.time_1), 2000);

d.addFrame(getResources().getDrawable(R.drawable.time_2), 2000);

showD.setImageDrawable(d);

d.start();

}

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值