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

Android編程之簡單逐幀動畫Frame的實現(xiàn)方法

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

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

1、逐幀動畫

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

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

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

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

代碼如下:

<?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>

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

3、布局文件:

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

<?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);只要選擇一個就可以,兩個都寫顯得累贅,主要功能是指定播放的資源圖片。

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

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

相關(guān)文章

最新評論