亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Android編程之簡(jiǎn)單逐幀動(dòng)畫Frame的實(shí)現(xiàn)方法

 更新時(shí)間:2015年12月16日 12:04:32   作者:Sunnyfans  
這篇文章主要介紹了Android編程之簡(jiǎn)單逐幀動(dòng)畫Frame的實(shí)現(xiàn)方法,結(jié)合實(shí)例較為詳細(xì)的分析了Android逐幀動(dòng)畫的原理、步驟與具體實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程之簡(jiǎn)單逐幀動(dòng)畫Frame的實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

1、逐幀動(dòng)畫

即是通過播放預(yù)先排序好的圖片來實(shí)現(xiàn)動(dòng)態(tài)的畫面,感覺像是放電影。

2、實(shí)現(xiàn)步驟:

① 在工程里面導(dǎo)入要播放的圖片。此簡(jiǎn)單例子中為start_icon1,2,3.

② 在工程res文件目錄下新建一個(gè)anim文件夾,在里面新建一個(gè)start_animation.xml格式文件,此文件用來定義動(dòng)畫播放圖片的順序及每一張圖片顯示停留時(shí)間。

代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
  android:oneshot="false">
  <item android:drawable="@drawable/start_icon1" android:duration="1000" />
  <item android:drawable="@drawable/start_icon2" android:duration="500" />
  <item android:drawable="@drawable/start_icon3" android:duration="600" />
</animation-list>

注:此藍(lán)色部分依次顯示的圖片,存放在drawable-mdpi文件下,一般1秒鐘播放24張圖片(幀)就感覺播放流暢了,即duration為40左右,默認(rèn)單位為毫秒。

3、布局文件:

布局文件中添加一ImageView控件,用來播放動(dòng)畫圖片。具體布局如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
  <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="開始" />
  <Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     android:layout_gravity="center"
    android:text="結(jié)束" />
  <ImageView
    android:id="@+id/image"
    android:background="@anim/start_animation"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"/>
</LinearLayout>

4、代碼部分:

public class TestActivity extends Activity
{
AnimationDrawable anim;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.start_screen);
ImageView image = (ImageView) findViewById(R.id.image);
// image.setBackgroundResource(R.anim.start_animation);
anim = (AnimationDrawable) image.getBackground();
Button start = (Button) findViewById(R.id.button1);
Button stop = (Button) findViewById(R.id.button2);
start.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
anim.start();
}
});
stop.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
anim.stop();
}
});
}
}

注:第三步中的android:background="@anim/start_animation"和第四步中的 image.setBackgroundResource(R.anim.start_animation);只要選擇一個(gè)就可以,兩個(gè)都寫顯得累贅,主要功能是指定播放的資源圖片。

小結(jié):這種應(yīng)用在實(shí)際應(yīng)用中應(yīng)該不會(huì)用到,對(duì)于初學(xué)著來說,拿著玩下還是蠻有意思的,不僅增強(qiáng)了對(duì)Android學(xué)習(xí)的興趣,同時(shí)也能加深對(duì)制造電影的一些了解

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論