2012-04-19 22 views
2

私はアンドロイド2.1にスプラッシュ画面を書いています。私はスプラッシュ画面で20個の画像を注文してほしい。私はアニメーションリストを使用しようとしましたが、それを行うことができませんでした。スプラッシュ画面のフレーム別アニメーション - Android 2.1

ここに私のコードです。さて、firstLoadingImage.pngというイメージがあります。 5000msの間しか表示されません。その後、myappactivityが始まります。しかし、この待機時間中にイメージソースを更新することはできませんでした。私はこれをどうやってできると思いますか?

SplashScreenActivity

package myapp.activity; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class SplashScreenActivity extends Activity { 
    protected boolean _active = true; 
    protected int _splashTime = 5000; // time to display the splash screen in ms 

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splashscreen); 

     Thread splashTread = new Thread() { 
      @Override 
      public void run() { 
       try { 
        int waited = 0; 
        while(_active && (waited < _splashTime)) { 
         sleep(100); 
         if(_active) { 
          waited += 100; 
         } 
        } 
       } catch(InterruptedException e) { 
        // do nothing 
       } finally { 
        finish(); 
        startActivity(new Intent(SplashScreenActivity.this, MyAppActivity.class)); 
        stop(); 
       } 
      } 
     }; 
     splashTread.start(); 
    } 

} 

splashscreen.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:id="@+id/linearLayout" 
    android:background="@drawable/loading_screen_background" > 

    <ImageView 
     android:id="@+id/firstLoadingImage" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/loading100" /> 

</LinearLayout> 

答えて

0

私の推測では、あなたのスプラッシュスレッドで睡眠を呼び出した後、関数runOnUiThread()を使用することです。 ImageViewの背景を変更するための実行可能クラスを作成し、おそらくこの関数で実行しますか? Activity.runOnUiThread()

1

フレームアニメーションはImageViewの背景にAnimationDrawableにそれを設定することによって達成することができます。

例:

final AnimationDrawable anim = new AnimationDrawable(); 
anim.addFrame(Context.getResources().getDrawable(R.drawable.resource_id_of_frame1, durationInMs); 
anim.addFrame(Context.getResources().getDrawable(R.drawable.resource_id_of_frame2, durationInMs); 
anim.addFrame(Context.getResources().getDrawable(R.drawable.resource_id_of_frame3, durationInMs); 
... 
anim.addFrame(Context.getResources().getDrawable(R.drawable.resource_id_of_framen, durationInMs); 
anim.setOneShot(false); 

ImageView myImageView = getImageViewToSet(); 
myImageView.setBackgroundDrawable(anim); 
myImageView.post(new Runnable(){ 
    public void run(){ 
     anim.start(); 
    } 
} 

だから、ImageViewであなたのスプラッシュ画面シンプルなレイアウトを作成または1つを作成し、レイアウトに追加します。それにAnimationDrawableを設定して実行してください。

関連する問題