分解gif图片的工具很多,我用的Photoshop。

用Photoshop打开gif图片,然后文件--->导出--->渲染视频即可。

相应设置点击渲染即可。然后会出来4张图片

然后把图片们放进资源文件夹中,我放在了res/raw中;

在drawable中建立一个xml文件

            
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
  3.     android:oneshot="false" > 
  4.     <item 
  5.         android:drawable="@raw/gj1" 
  6.         android:duration="100"/> 
  7.     <item 
  8.         android:drawable="@raw/gj2" 
  9.         android:duration="100"/> 
  10.     <item 
  11.         android:drawable="@raw/gj3" 
  12.         android:duration="100"/> 
  13.     <item 
  14.         android:drawable="@raw/gj4" 
  15.         android:duration="100"/> 
  16.  
  17. animation-list> 

android:oneshot:true播放一次,false重复播放

android:duration:事件间隔

然后在需要用到的控件中

            
  1. <ImageView 
  2.        android:id="@+id/iv_gj" 
  3.        android:layout_width="wrap_content" 
  4.        android:layout_height="wrap_content" 
  5.        android:background="@drawable/gif_gj" /> 

java代码:

            
  1. package com.example.giftest; 
  2.  
  3. import android.app.Activity; 
  4. import android.graphics.drawable.AnimationDrawable; 
  5. import android.os.Bundle; 
  6. import android.widget.ImageView; 
  7.  
  8. public class MainActivity extends Activity { 
  9.  
  10.     private ImageView iv_gj; 
  11.  
  12.     @Override 
  13.     protected void onCreate(Bundle savedInstanceState) { 
  14.         super.onCreate(savedInstanceState); 
  15.         setContentView(R.layout.activity_main); 
  16.         iv_gj = (ImageView) findViewById(R.id.iv_gj); 
  17.     } 
  18.  
  19.     /* 
  20.      * 如果想让动画一开始就播放,可以重写此方法 
  21.      */ 
  22.     @Override 
  23.     public void onWindowFocusChanged(boolean hasFocus) { 
  24.          
  25.         /* 触发动画 */ 
  26.         AnimationDrawable ad = (AnimationDrawable) iv_gj.getBackground();
  27.  
  28. //如果xml中是这样设置的:android:src="@drawable/gif_gj",则使用下面的方法 //AnimationDrawable ad = (AnimationDrawable) iv_gj.getDrawable();
  29.         ad.stop(); 
  30.         ad.start(); 
  31.         /* ***** */ 
  32.          
  33.         super.onWindowFocusChanged(hasFocus); 
  34.     } 
  35.  

 

更多相关文章

  1. 设置提示信息,输入值类型,输入框引入图片,设置输入框的形状
  2. android保存文件到手机内存
  3. Android(安卓)boot.img介绍
  4. Android(安卓)NDK工程的编译和链接调试
  5. android数字证书-签名(步骤)
  6. Android版本适配问题处理
  7. Android的多媒体框架Opencore代码阅读
  8. android中九宫格布局的实现
  9. 初识android

随机推荐

  1. JS函数类型及数据类型
  2. 学习了事件的冒泡与事件的委托代理以及表
  3. android Drawable转Bitmap| Bitmap转byte
  4. Android(安卓)-- 图片画画板(canvas、pain
  5. android之Tab选项卡控件
  6. Android(安卓)实现Activity后台运行
  7. android radiobutton选中字体颜色改变的
  8. [置顶] Android(安卓)GridView
  9. 【Android实战】Android中处理崩溃异常
  10. android facebook authorize 时禁止调用f