[Android实例] [附实例]Android 动画效果二 Frame Animation 动画专题研究 二 [复制链接]

===============eoeAndroid社区推荐:=======================

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
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.     android:prientation="vertical" android:layout_width="fill_parent"
  4.     android:layout_height="fill_parent">
  5.     <LinearLayout android:prientation="horizontal"
  6.         android:layout_width="fill_parent" android:layout_height="wrap_content"
  7.         android:background="@drawable/bt_group_back" android:layout_marginTop="10px">
  8.         <Button android:text="播放动画" android:layout_width="100px"
  9.             android:id="@+id/Button_start" android:layout_height="fill_parent"></Button>
  10.         <Button android:layout_width="100px" android:text="停止动画"
  11.             android:id="@+id/Button_stop" android:layout_height="fill_parent"></Button>
  12.         <CheckBox android:text="动画重复" android:layout_width="100px"
  13.             android:id="@+id/CheckBox_ifCycle_orNot" style="?android:attr/starStyle"
  14.             android:layout_height="fill_parent"></CheckBox>
  15.     </LinearLayout>
  16.     <ImageView android:id="@+id/rocket_image"
  17.         android:layout_width="80px" android:layout_height="80px"
  18.         android:background="@drawable/android_large"
  19.         android:layout_marginLeft="100dp" android:layout_marginTop="100dp"></ImageView>
  20. </LinearLayout>
复制代码
  • 找几个动态图片,把它分成单个图。(主要是为了讲解/是用Frame Animation效果,AnimationDrawable)


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

  2. import android.app.Activity;
  3. import android.graphics.drawable.AnimationDrawable;
  4. import android.os.Bundle;
  5. import android.view.MotionEvent;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.CheckBox;
  9. import android.widget.ImageView;
  10. import android.widget.Toast;
  11. public class myFrameAnimatino extends Activity implements Button.OnClickListener {
  12.     /** Called when the activity is first created. */
  13.     AnimationDrawable frameAnimation;
  14.     /*
  15.      * 声明AnimationDrawable 可绘制动画 对象frameAnimation
  16.      */
  17.     ImageView myImage;
  18.     /*
  19.      * 图片View ImageView
  20.      */
  21.     Button start,stop;
  22.     CheckBox Cycle;
  23.     boolean isChecked_cycle=true;
  24.     /*
  25.      * (non-Javadoc)
  26.      * [url=home.php?mod=space&uid=133757]@see[/url] android.app.Activity#onCreate(android.os.Bundle)
  27.      */
  28.     @Override
  29.     public void onCreate(Bundle savedInstanceState) {
  30.         super.onCreate(savedInstanceState);
  31.         setContentView(R.layout.main);
  32.         
  33.         start=(Button) findViewById(R.id.Button_start);
  34.         stop=(Button) findViewById(R.id.Button_stop);
  35.         Cycle=(CheckBox) findViewById(R.id.CheckBox_ifCycle_orNot);
  36.         /*
  37.          * findViewById()从XML中获取 Button  CheckBox
  38.          */
  39.         
  40.         myImage = (ImageView) findViewById(R.id.rocket_image);
  41.         /*
  42.          * findViewById()从XML中获取ImageView 对象myImage
  43.          */
  44.         myImage.setBackgroundResource(R.anim.myframeanimation);
  45.         /*
  46.          * ImageView.setBackgroundResource()设置 图片View的背景图片 
  47.          * 这里是把帧动画 myframeanimation加到 图片View的背景中
  48.          */
  49.         frameAnimation = (AnimationDrawable) myImage.getBackground();
  50.         /*
  51.          * myImage.getBackground()获得背景的Drawable的对象,转换成AnimationDrawable
  52.          */
  53.         
  54.         start.setOnClickListener(this);
  55.         stop.setOnClickListener(this);
  56.     }
  57.     /*
  58.      * (non-Javadoc)
  59.      * @see android.app.Activity#onTouchEvent(android.view.MotionEvent)
  60.      */
  61.     @Override
  62.     public boolean onTouchEvent(MotionEvent event) {
  63.         frameAnimation.setOneShot(isChecked_cycle);
  64.         /*
  65.          * 添加触摸事件处理方法
  66.          */
  67.         // TODO Auto-generated method stub
  68.         if(event.getAction()==MotionEvent.ACTION_DOWN){
  69.             /*
  70.              * MotionEvent.getAction()获取事件动作
  71.              * MotionEvent.ACTION_DOWN 向下的手势动作
  72.              */

  73.         /*event.getAction() 返回正被执行的动作种类:
  74.          * 是     ACTION_DOWN, ACTION_MOVE, ACTION_UP, 或 ACTION_CANCEL中的一个.
  75.          */
  76.             frameAnimation.start();
  77.             /*
  78.              * 启动帧动画效果
  79.              */
  80.             return true;

  81.         }
  82.         return super.onTouchEvent(event);
  83.     }
  84.     /*
  85.      * (non-Javadoc)
  86.      * @see android.view.View.OnClickListener#onClick(android.view.View)
  87.      */
  88.     @Override
  89.     public void onClick(View button) {
  90.         // TODO Auto-generated method stub
  91.         switch (button.getId()) {
  92.         case R.id.Button_start:{
  93.             if(Cycle.isChecked()){
  94.                 Toast.makeText(this, "动画重复", Toast.LENGTH_LONG).show();
  95.                 isChecked_cycle=false;
  96.             }else{
  97.                 Toast.makeText(this, "不重复", Toast.LENGTH_LONG).show();
  98.                 isChecked_cycle=true;
  99.             }
  100.             /*
  101.              * 复选按钮选中,  动画重复播放,  AnimationDrawable.setOneShot(false)
  102.              * 复选按钮未选中,动画不重复播放,AnimationDrawable.setOneShot(true)
  103.              */
  104.             
  105.             frameAnimation.setOneShot(isChecked_cycle);
  106.             /*
  107.              * 设置重复与否
  108.              */
  109.             frameAnimation.start();
  110.             /*
  111.              *启动帧动画效果
  112.              */
  113.             
  114.         }
  115.             break;
  116.         case R.id.Button_stop:{
  117.             if(frameAnimation.isRunning()){
  118.                 /*
  119.                  * AnimationDrawable.isRunning(),判断帧动画是否在运行,true---运行中
  120.                  * 如果动画正在运行,可以停止
  121.                  */
  122.                 frameAnimation.stop();
  123.                 /*
  124.                  *停止帧动画效果 
  125.                  */
  126.             }
  127.             
  128.         }
  129.             break;
  130.         default:
  131.             break;
  132.         }
  133.     }
  134. }
复制代码
  • 运行结果

1.png 
2.png 


  • 源码

  myFrameAnimation.rar (171.54 KB, 下载次数: 3864) 
================更多内容推荐===================================

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

实例教程 会员贡献索引贴
http://www.eoeandroid.com/thread-1987-1-1.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Go语言(也称为Golang)是由Google开发的一种静态强类型、编译型的编程语言。它旨在成为一门简单、高效、安全和并发的编程语言,特别适用于构建高性能的服务器和分布式系统。以下是Go语言的一些主要特点和优势: 简洁性:Go语言的语法简单直观,易于学习和使用。它避免了复杂的语法特性,如继承、重载等,转而采用组合和接口来实现代码的复用和扩展。 高性能:Go语言具有出色的性能,可以媲美C和C++。它使用静态类型系统和编译型语言的优势,能够生成高效的机器码。 并发性:Go语言内置了对并发的支持,通过轻量级的goroutine和channel机制,可以轻松实现并发编程。这使得Go语言在构建高性能的服务器和分布式系统时具有天然的优势。 安全性:Go语言具有强大的类型系统和内存管理机制,能够减少运行时错误和内存泄漏等问题。它还支持编译时检查,可以在编译阶段就发现潜在的问题。 标准库:Go语言的标准库非常丰富,包含了大量的实用功能和工具,如网络编程、文件操作、加密解密等。这使得开发者可以更加专注于业务逻辑的实现,而无需花费太多时间在底层功能的实现上。 跨平台:Go语言支持多种操作系统和平台,包括Windows、Linux、macOS等。它使用统一的构建系统(如Go Modules),可以轻松地跨平台编译和运行代码。 开源和社区支持:Go语言是开源的,具有庞大的社区支持和丰富的资源。开发者可以通过社区获取帮助、分享经验和学习资料。 总之,Go语言是一种简单、高效、安全、并发的编程语言,特别适用于构建高性能的服务器和分布式系统。如果你正在寻找一种易于学习和使用的编程语言,并且需要处理大量的并发请求和数据,那么Go语言可能是一个不错的选择。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值