• Android成长之路-实现简单动画


     

    实现简单动画:

    在drawable目录中放入图片,

    并且创建xml文件 frame.xml 存入图片,如下:

      1. <pre class="html" name="code"><?xml version="1.0" encoding="utf-8"?>  
      2. <animation-list xmlns:android="http://schemas.android.com/apk/res/android"  
      3.     android:oneshot="false">  
      4.     <!-- 可以重复添加,实现循环 -->  
      5.     <!-- android:duration="100"设置的是图片持续的时间长短 -->  
      6.     <item android:drawable="@drawable/girl_1" android:duration="100" />  
      7.     <item android:drawable="@drawable/girl_2" android:duration="100" />  
      8.     <item android:drawable="@drawable/girl_3" android:duration="100" />  
      9.     <item android:drawable="@drawable/girl_4" android:duration="100" />  
      10.     <item android:drawable="@drawable/girl_5" android:duration="100" />  
      11.     <item android:drawable="@drawable/girl_6" android:duration="200" />  
      12.     <item android:drawable="@drawable/girl_7" android:duration="300" />  
      13.     <item android:drawable="@drawable/girl_6" android:duration="200" />  
      14.     <item android:drawable="@drawable/girl_7" android:duration="300" />  
      15.     <item android:drawable="@drawable/girl_8" android:duration="200" />  
      16.     <item android:drawable="@drawable/girl_9" android:duration="100" />  
      17.     <item android:drawable="@drawable/girl_10" android:duration="100" />  
      18.     <item android:drawable="@drawable/girl_11" android:duration="100" />  
      19.   
      20. </animation-list>  
      21.   
      22.   
      23. </pre><br>  
      24. <pre></pre>  
      25. <h3><a name="t3"></a>然后定义一个布局frame_layout.xml:</h3>  
      26. <pre class="html" name="code"><?xml version="1.0" encoding="utf-8"?>  
      27. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
      28.     android:layout_width="match_parent"  
      29.     android:layout_height="match_parent"  
      30.     android:orientation="vertical"  
      31.     android:gravity="center" >  
      32.   
      33.     <!-- 承载图片 -->  
      34.     <ImageView  
      35.         android:id="@+id/frameIV"  
      36.         android:layout_width="wrap_content"  
      37.         android:layout_height="wrap_content"  
      38.         />  
      39.   
      40. </LinearLayout></pre>  
      41. <p><br>  
      42.  </p>  
      43. <h3><a name="t4"></a>然后写activity类,FrameActivity.java:</h3>  
      44. <pre class="java" name="code">package cn.class3g.animation;  
      45.   
      46. import android.app.Activity;  
      47. import android.graphics.drawable.AnimationDrawable;  
      48. import android.os.Bundle;  
      49. import android.view.MotionEvent;  
      50. import android.widget.ImageView;  
      51.   
      52. public class FrameActivity extends Activity {  
      53.   
      54.     AnimationDrawable attackAnimation;//定义动画对象  
      55.     ImageView frameIV;  
      56.       
      57.     protected void onCreate(Bundle savedInstanceState) {  
      58.         super.onCreate(savedInstanceState);  
      59.         this.setContentView(R.layout.frame_layout);  
      60.           
      61.         init();  
      62.     }  
      63.   
      64.     private void init() {  
      65.         frameIV = (ImageView) this.findViewById(R.id.frameIV);  
      66.         frameIV.setBackgroundResource(R.drawable.frame);//得到图片并添加到布局中(当作背景图片)  
      67.         attackAnimation = (AnimationDrawable) frameIV.getBackground();//得到背景图片给动画对象  
      68.           
      69.     }  
      70.     //点击屏幕触发  
      71.     public boolean onTouchEvent(MotionEvent event) {  
      72.         if(event.getAction() == MotionEvent.ACTION_DOWN){  
      73.             attackAnimation.start();//点击屏幕后启动动画  
      74.         }  
      75.         return super.onTouchEvent(event);  
      76.     }  
      77.       
      78.       
      79.   
      80. }  
      81. </pre>  
      82. <p><br>  
      83.  </p>  
      84. <h3><a name="t5"></a>此时,在清单中注册后就可以运行并实现了</h3> 
  • 相关阅读:
    Eclipse搭建springboot项目(八)拦截器、过滤器、监听器
    JAVA LOG
    Eclipse搭建springboot项目(七)启动方式
    Eclipse搭建springboot项目(六)全局异常
    Eclipse搭建springboot项目(五)单元测试
    Eclipse搭建springboot项目(四)热部署
    Eclipse搭建springboot项目(三)配置文件自动注入+文件上传需求
    报错
    Eclipse搭建springboot项目(二)springboot目录
    Linux window查询网络端口
  • 原文地址:https://www.cnblogs.com/xgjblog/p/3877949.html
Copyright © 2020-2023  润新知