欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 逐幀動(dòng)畫創(chuàng)建實(shí)例詳解

 更新時(shí)間:2017年08月30日 14:36:18   投稿:lqh  
這篇文章主要介紹了Android 逐幀動(dòng)畫創(chuàng)建實(shí)例詳解的相關(guān)資料,這里主要說(shuō)明Android 動(dòng)畫的創(chuàng)建及使用方法,希望通過(guò)此文能幫助到大家,需要的朋友可以參考下

Android 逐幀動(dòng)畫創(chuàng)建實(shí)例詳解

前言:

我們看早期電影的時(shí)候,電影通常是一張一張播放,用我們現(xiàn)在專有名詞來(lái)說(shuō),就是一幀幀來(lái),安卓同樣有這樣動(dòng)畫效果的編排形式。

那么我們先定義逐幀動(dòng)畫xml文件

<?xml version="1.0" encoding="utf-8"?> 
<animation-list 
  xmlns:android="http://schemas.android.com/apk/res/android" 
  android:oneshot="true"> 
 
  <item 
    android:drawable="@drawable/pic1" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic2" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic3" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic4" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic5" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic6" 
    android:duration="200" /> 
  <item 
    android:drawable="@drawable/pic7" 
    android:duration="200" /> 
   <item 
    android:drawable="@drawable/pic8" 
    android:duration="200" /> 
   <item 
    android:drawable="@drawable/pic8" 
    android:duration="200" /> 
    
 
 
</animation-list> 

main.xml

<ImageView 
    android:id="@+id/pic" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="98dp" 
    android:layout_marginTop="69dp" 
     /> 
 
  <Button 
    android:id="@+id/button1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_marginBottom="54dp" 
    android:layout_marginLeft="98dp" 
    android:onClick="startMovie" 
    android:text="開(kāi)始播放電影" /> 
 

Activiy代碼:

public class MyAnimationDemo extends Activity { 
 
  private AnimationDrawable draw=null; 
  private ImageView image; 
  protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_my_animation_demo); 
    image=(ImageView)super.findViewById(R.id.pic); 
  } 
 
  public void startMovie(View v){ 
    image.setBackgroundResource(R.anim.oldvideo);//第一步,設(shè)置圖片資源 
    draw=(AnimationDrawable)image.getBackground();//取得圖片背景的Drawable 
    draw.setOneShot(false);//動(dòng)畫執(zhí)行次數(shù) 
    draw.start();//開(kāi)始動(dòng)畫 
     
  } 
 
} 
 

這里我們看到,

第一步,設(shè)置圖片背景資源

第二步,設(shè)置得到圖片背景的draw

第三步,設(shè)置draw參數(shù),并start()

實(shí)現(xiàn)效果如下,間隔0.2秒即換圖,實(shí)現(xiàn)老電影動(dòng)畫效果


 

 以上就是Android 逐幀動(dòng)畫的實(shí)例詳解,如有疑問(wèn)請(qǐng)留言或到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論