Android 动画

http://www.eoeandroid.com/thread-775-1-1.html

 

 

Android 开发笔记 动画效果 --Animation 动画专题研究 一
http://www.eoeandroid.com/thread-564-1-1.html

Android 开发笔记 动画效果 --Animation 动画专题研究 一 (转帖)
http://www.eoeandroid.com/thread-28941-1-1.html

史上最全的动画效果 --Android Animation 总汇
http://www.eoeandroid.com/thread-653-1-1.html

ViewPager多页面滑动切换以及动画效果(版主加个精呗~)
http://www.eoeandroid.com/thread-157771-1-1.html

===============帖子正文==============================

动画专题研究 二

动画效果二 ----Frame Animation


  • 新建工程 myFrameAnimation

  • 在main.xml布局中添加view子类,调整一下,效果如下:

a.png
2009-6-17 05:10 上传
下载附件(19.14 KB)

 

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

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

    android:prientation="vertical" android:layout_width="fill_parent"

    android:layout_height="fill_parent">

    <LinearLayout android:prientation="horizontal"

        android:layout_width="fill_parent" android:layout_height="wrap_content"

        android:background="@drawable/bt_group_back" android:layout_marginTop="10px">

        <Button android:text="播放动画" android:layout_width="100px"

            android:id="@+id/Button_start" android:layout_height="fill_parent"></Button>

        <Button android:layout_width="100px" android:text="停止动画"

            android:id="@+id/Button_stop" android:layout_height="fill_parent"></Button>

        <CheckBox android:text="动画重复" android:layout_width="100px"

            android:id="@+id/CheckBox_ifCycle_orNot" style="?android:attr/starStyle"

            android:layout_height="fill_parent"></CheckBox>

    </LinearLayout>

    <ImageView android:id="@+id/rocket_image"

        android:layout_width="80px" android:layout_height="80px"

        android:background="@drawable/android_large"

        android:layout_marginLeft="100dp" android:layout_marginTop="100dp"></ImageView>

</LinearLayout>


 

  • 找几个动态图片,把它分成单个图。(主要是为了讲解/是用Frame Animation效果,AnimationDrawable)


  • 修改mainActivity.java的代码
package zyf.my.frame.animation;



import android.app.Activity;

import android.graphics.drawable.AnimationDrawable;

import android.os.Bundle;

import android.view.MotionEvent;

import android.view.View;

import android.widget.Button;

import android.widget.CheckBox;

import android.widget.ImageView;

import android.widget.Toast;

public class myFrameAnimatino extends Activity implements Button.OnClickListener {

    /** Called when the activity is first created. */

    AnimationDrawable frameAnimation;

    /*

     * 声明AnimationDrawable 可绘制动画 对象frameAnimation

     */

    ImageView myImage;

    /*

     * 图片View ImageView

     */

    Button start,stop;

    CheckBox Cycle;

    boolean isChecked_cycle=true;

    /*

     * (non-Javadoc)

     * [url=home.php?mod=space&uid=133757]@see[/url] android.app.Activity#onCreate(android.os.Bundle)

     */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

        start=(Button) findViewById(R.id.Button_start);

        stop=(Button) findViewById(R.id.Button_stop);

        Cycle=(CheckBox) findViewById(R.id.CheckBox_ifCycle_orNot);

        /*

         * findViewById()从XML中获取 Button  CheckBox

         */

        

        myImage = (ImageView) findViewById(R.id.rocket_image);

        /*

         * findViewById()从XML中获取ImageView 对象myImage

         */

        myImage.setBackgroundResource(R.anim.myframeanimation);

        /*

         * ImageView.setBackgroundResource()设置 图片View的背景图片 

         * 这里是把帧动画 myframeanimation加到 图片View的背景中

         */

        frameAnimation = (AnimationDrawable) myImage.getBackground();

        /*

         * myImage.getBackground()获得背景的Drawable的对象,转换成AnimationDrawable

         */

        

        start.setOnClickListener(this);

        stop.setOnClickListener(this);

    }

    /*

     * (non-Javadoc)

     * @see android.app.Activity#onTouchEvent(android.view.MotionEvent)

     */

    @Override

    public boolean onTouchEvent(MotionEvent event) {

        frameAnimation.setOneShot(isChecked_cycle);

        /*

         * 添加触摸事件处理方法

         */

        // TODO Auto-generated method stub

        if(event.getAction()==MotionEvent.ACTION_DOWN){

            /*

             * MotionEvent.getAction()获取事件动作

             * MotionEvent.ACTION_DOWN 向下的手势动作

             */



        /*event.getAction() 返回正被执行的动作种类:

         * 是     ACTION_DOWN, ACTION_MOVE, ACTION_UP, 或 ACTION_CANCEL中的一个.

         */

            frameAnimation.start();

            /*

             * 启动帧动画效果

             */

            return true;



        }

        return super.onTouchEvent(event);

    }

    /*

     * (non-Javadoc)

     * @see android.view.View.OnClickListener#onClick(android.view.View)

     */

    @Override

    public void onClick(View button) {

        // TODO Auto-generated method stub

        switch (button.getId()) {

        case R.id.Button_start:{

            if(Cycle.isChecked()){

                Toast.makeText(this, "动画重复", Toast.LENGTH_LONG).show();

                isChecked_cycle=false;

            }else{

                Toast.makeText(this, "不重复", Toast.LENGTH_LONG).show();

                isChecked_cycle=true;

            }

            /*

             * 复选按钮选中,  动画重复播放,  AnimationDrawable.setOneShot(false)

             * 复选按钮未选中,动画不重复播放,AnimationDrawable.setOneShot(true)

             */

            

            frameAnimation.setOneShot(isChecked_cycle);

            /*

             * 设置重复与否

             */

            frameAnimation.start();

            /*

             *启动帧动画效果

             */

            

        }

            break;

        case R.id.Button_stop:{

            if(frameAnimation.isRunning()){

                /*

                 * AnimationDrawable.isRunning(),判断帧动画是否在运行,true---运行中

                 * 如果动画正在运行,可以停止

                 */

                frameAnimation.stop();

                /*

                 *停止帧动画效果 

                 */

            }

            

        }

            break;

        default:

            break;

        }

    }

}


 

 

  • 运行结果

1.png
2009-6-17 05:10 上传
下载附件(32.89 KB)

2.png
2009-6-17 05:10 上传
下载附件(29.18 KB)



  • 源码

myFrameAnimation.rar(171.54 KB, 下载次数: 3600)
2009-6-17 05:10 上传
点击文件名下载附件
下载积分: e币 -1 元

================更多内容推荐===================================

自己仿照Path照片分享软件的Button动画效果——欢迎指教
http://www.eoeandroid.com/thread-148107-1-1.html

实例教程 会员贡献索引贴
http://www.eoeandroid.com/thread-1987-1-1.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值