zoukankan      html  css  js  c++  java
  • Android只播放gif动画

    使用easygifanimator软件把gif动画打散为图片。

    第一步:先上图片素材,以下素材放到res/drawable目录下:

    转:http://blog.csdn.net/aminfo/article/details/7847761

    图片素材:

    文件名称:

    icon1.png

    icon1.png

    icon1.png

    icon1.png

    icon1.png

    icon1.png

    第二步:上动画Animation-list帧布局文件,有2个,一个是按顺序显示动画,一个是倒序显示动画,文件存放在res/drawable目录下

    顺序显示动画文件:animation1.xml

    [html] view plaincopy
     
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <!--   
    3.     根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画  
    4.     根标签下,通过item标签对动画中的每一个图片进行声明  
    5.     android:duration 表示展示所用的该图片的时间长度  
    6.  -->  
    7. <animation-list  
    8.   xmlns:android="http://schemas.android.com/apk/res/android"  
    9.   android:oneshot="true"  
    10.   >  
    11.     <item android:drawable="@drawable/icon1" android:duration="150"></item>  
    12.     <item android:drawable="@drawable/icon2" android:duration="150"></item>  
    13.     <item android:drawable="@drawable/icon3" android:duration="150"></item>  
    14.     <item android:drawable="@drawable/icon4" android:duration="150"></item>  
    15.     <item android:drawable="@drawable/icon5" android:duration="150"></item>  
    16.     <item android:drawable="@drawable/icon6" android:duration="150"></item>  
    17. </animation-list>  

    倒序显示动画文件:animation2.xml

    [html] view plaincopy
     
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <!--   
    3.     根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画  
    4.     根标签下,通过item标签对动画中的每一个图片进行声明  
    5.     android:duration 表示展示所用的该图片的时间长度  
    6.  -->  
    7. <animation-list  
    8.   xmlns:android="http://schemas.android.com/apk/res/android"  
    9.   android:oneshot="true"  
    10.   >  
    11.     <item android:drawable="@drawable/icon6" android:duration="150"></item>  
    12.     <item android:drawable="@drawable/icon5" android:duration="150"></item>  
    13.     <item android:drawable="@drawable/icon4" android:duration="150"></item>  
    14.     <item android:drawable="@drawable/icon3" android:duration="150"></item>  
    15.     <item android:drawable="@drawable/icon2" android:duration="150"></item>  
    16.     <item android:drawable="@drawable/icon1" android:duration="150"></item>  
    17. </animation-list>  


    第三步:上布局文件,放在res/layout目录下,文件名main.xml

    [html] view plaincopy
     
    1. <?xml version="1.0" encoding="utf-8"?>  
    2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    3.    android:layout_width="fill_parent"  
    4.    android:layout_height="fill_parent"  
    5.    android:orientation="vertical">  
    6.      
    7.     <ImageView android:id="@+id/animationIV"  
    8.             android:layout_width="wrap_content"  
    9.             android:layout_height="wrap_content"  
    10.             android:padding="5px"  
    11.             android:src="@drawable/animation1"/>   
    12.               
    13.     <Button android:id="@+id/buttonA"  
    14.         android:layout_width="wrap_content"  
    15.         android:layout_height="wrap_content"  
    16.         android:padding="5px"  
    17.         android:text="顺序显示" />  
    18.       
    19.     <Button android:id="@+id/buttonB"  
    20.         android:layout_width="wrap_content"  
    21.         android:layout_height="wrap_content"  
    22.         android:padding="5px"  
    23.         android:text="停止" />  
    24.       
    25.     <Button android:id="@+id/buttonC"  
    26.         android:layout_width="wrap_content"  
    27.         android:layout_height="wrap_content"  
    28.         android:padding="5px"  
    29.         android:text="倒序显示" />  
    30.   
    31. </LinearLayout>  

    第四步:上Activity文件,文件名:MainActivity.java

    [java] view plaincopy
     
      1. package org.shuxiang.test;  
      2.   
      3. import android.app.Activity;  
      4. import android.graphics.drawable.AnimationDrawable;  
      5.   
      6. import android.os.Bundle;  
      7. import android.view.View;  
      8. import android.view.View.OnClickListener;  
      9. import android.view.Window;  
      10. import android.widget.Button;  
      11. import android.widget.ImageView;  
      12.   
      13. public class Activity10 extends Activity  
      14. {  
      15.     private ImageView animationIV;  
      16.     private Button buttonA, buttonB, buttonC;  
      17.     private AnimationDrawable animationDrawable;  
      18.     @Override  
      19.     public void onCreate(Bundle savedInstanceState) {  
      20.         super.onCreate(savedInstanceState);  
      21.         requestWindowFeature(Window.FEATURE_NO_TITLE);  
      22.         setContentView(R.layout.test10);  
      23.          
      24.           
      25.         animationIV = (ImageView) findViewById(R.id.animationIV);  
      26.         buttonA = (Button) findViewById(R.id.buttonA);  
      27.         buttonB = (Button) findViewById(R.id.buttonB);  
      28.         buttonC = (Button) findViewById(R.id.buttonC);  
      29.           
      30.         buttonA.setOnClickListener(new OnClickListener()  
      31.         {  
      32.             @Override  
      33.             public void onClick(View v) {  
      34.                 // TODO Auto-generated method stub  
      35.                 animationIV.setImageResource(R.drawable.animation1);  
      36.                 animationDrawable = (AnimationDrawable) animationIV.getDrawable();  
      37.                 animationDrawable.start();  
      38.             }  
      39.               
      40.         });   
      41.           
      42.         buttonB.setOnClickListener(new OnClickListener()  
      43.         {  
      44.             @Override  
      45.             public void onClick(View v) {  
      46.                 // TODO Auto-generated method stub  
      47.                 animationDrawable = (AnimationDrawable) animationIV.getDrawable();  
      48.                 animationDrawable.stop();  
      49.             }  
      50.               
      51.         });  
      52.           
      53.         buttonC.setOnClickListener(new OnClickListener()  
      54.         {  
      55.             @Override  
      56.             public void onClick(View v) {  
      57.                 // TODO Auto-generated method stub  
      58.                 animationIV.setImageResource(R.drawable.animation2);  
      59.                 animationDrawable = (AnimationDrawable) animationIV.getDrawable();  
      60.                 animationDrawable.start();  
      61.             }             
      62.         });          
      63.     }  
      64. }  
  • 相关阅读:
    转:NetBackup 7.5:放下磁带,才能走更远?
    HP NIC Teaming技术探讨
    Lagged Mailbox Database Copy in Exchange 2010
    Netbackup SSO
    Move or migrate user accounts from old Linux server to a new Linux server
    转:VMware vsphere 5.0新体验总结
    VMware vSphere: What’s New [V 5.1]
    windows server 2008 R2上安装MRTG指南
    VMware vCenter vDS 分布式交换机
    VMware vSphere: Install, Configure, Manage [V5.0]
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/3183463.html
Copyright © 2011-2022 走看看