国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

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

2019-12-12 02:08:04
字體:
供稿:網(wǎng)友

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

前言:

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

那么我們先定義逐幀動畫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="開始播放電影" />  

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);//動畫執(zhí)行次數(shù)     draw.start();//開始動畫        }  }  

這里我們看到,

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

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

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

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


 

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳春市| 洪雅县| 分宜县| 土默特左旗| 东宁县| 响水县| 大竹县| 杨浦区| 定南县| 漾濞| 鄢陵县| 德钦县| 峨山| 定西市| 栾城县| 文水县| 洛宁县| 永顺县| 安达市| 东乌珠穆沁旗| 江津市| 宁阳县| 石棉县| 龙井市| 成安县| 襄樊市| 商都县| 通河县| 安宁市| 康马县| 石狮市| 旌德县| 铁岭市| 康定县| 桃园县| 北川| 大竹县| 盱眙县| 彩票| 马边| 丹阳市|