码迷,mamicode.com
首页 > 移动开发 > 详细

android104 帧动画,补间动画,属性动画

时间:2015-11-18 21:30:33      阅读:223      评论:0      收藏:0      [点我收藏+]

标签:

##帧动画FrameAnimation
* 多张图片快速切换,形成动画效果
* 帧动画使用xml定义

package com.itheima.frameanimation;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.Menu;
import android.widget.ImageView;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        ImageView iv = (ImageView) findViewById(R.id.iv);
        //把帧动画的资源文件指定为iv的背景
        iv.setBackgroundResource(R.drawable.frameanimation);
        //获取iv的背景
        AnimationDrawable ad = (AnimationDrawable) iv.getBackground();
        ad.start();
    }


}
/*
drawable文件里的frameanimation.xml
<?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/g1" android:duration="200" />   每个图片停留200毫秒,
    <item android:drawable="@drawable/g2" android:duration="200" />
    <item android:drawable="@drawable/g3" android:duration="200" />
    <item android:drawable="@drawable/g4" android:duration="200" />
    <item android:drawable="@drawable/g5" android:duration="200" />
    <item android:drawable="@drawable/g6" android:duration="300" />
    <item android:drawable="@drawable/g7" android:duration="300" />
    <item android:drawable="@drawable/g8" android:duration="300" />
    <item android:drawable="@drawable/g9" android:duration="200" />
    <item android:drawable="@drawable/g10" android:duration="200" />
    <item android:drawable="@drawable/g11" android:duration="200" />
</animation-list>
*/

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

</RelativeLayout>

 

android104 帧动画,补间动画,属性动画

标签:

原文地址:http://www.cnblogs.com/yaowen/p/4975822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!