2015-10-06 84 views
1

我是android初學者。我需要在應用程序中實現逐幀動畫,但是它已經完成了我不知道請給我一個完整的框架框架動畫的例子。這是我能想到的,現在ANDROID - Frame By Frame動畫

+0

您可以檢查http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html和https://www.bignerdranch.com/blog/frame-animations-in-android/ – Aayushi

回答

2

嗨,你可以通過這一步做到這一點。

第1步:將圖像插入需要構圖的可繪製文件夾中。

步驟2:爲FrameByFrame動畫的配置創建一個xml,並將其放置到res/drawable文件夾中。 這裏有兩個圖像用於動畫是f1和f2。 android:持續時間定義更改幀的時間(以毫秒爲單位)。

<?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/f1" 
     android:duration="50"/> 
    <item 
     android:drawable="@drawable/f2" 
     android:duration="50"/> 
</animation-list> 

3步:創建main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="${packageName}.${activityClass}" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</RelativeLayout> 

第4步:在MainActivity.java

最後執行
public class MainActivity extends Activity { 
ImageView iv; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     // Imageview in which images load one by one like Frame By Frame 
     iv = (ImageView) findViewById(R.id.imageView1); 
     //Bind xml which is configure animation. 
     AnimationDrawable ad = (AnimationDrawable) getResources().getDrawable(
      R.drawable.sam); 
     iv.setBackgroundDrawable(ad); 
     //Start animation 
     ad.start(); 
     //For stop animation you can use ad.stop(); 
    } 
} 
0

2種方式是:

  1. 嘗試創建可繪製的動畫列表,並使用它們
  2. 試着畫使用畫布框在Android