2013-02-22 70 views
0

我一直在尋找通過這個問題和答案,但沒有發現任何有幫助。我有13 png。圖像,我試圖在我的啓動畫面中一個接一個地運行。以下是我正在使用的代碼。需要一個教程或幫助按框架啓動畫面?

splash.xml

<ImageView 
android:contentDescription="@string/desc" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:id="@+id/logo" 
android:background="@drawable/logo" /> 

splash.java

public class Splash extends Activity{ 
Animation animation; 
MediaPlayer ourSong; 

@Override 
public void onAttachedToWindow() { 
    // TODO Auto-generated method stub 
    super.onAttachedToWindow(); 
    Window window = getWindow(); 
    window.setFormat(PixelFormat.RGBA_8888); 
} 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splash); 
    ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound); 
    ourSong.start(); 
    Thread timer = new Thread(){ 
     public void run(){ 
      try{ 
       sleep(7000); 
      } catch (InterruptedException e){ 
       e.printStackTrace(); 
      }finally{ 
       Intent openStartingPoint = new Intent("com.thegoodwarren.lonte.STARTINGPOINT"); 
       startActivity(openStartingPoint); 
      } 
     } 
    }; 
    timer.start(); 

    StartAnimations(); 
} 


private void StartAnimations() { 
    // TODO Auto-generated method stub 
    Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha); 
    anim.reset(); 
    LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay); 
    l.clearAnimation(); 
    l.startAnimation(anim); 

    anim = AnimationUtils.loadAnimation(this, R.anim.translate); 
    anim.reset(); 
    ImageView iv = (ImageView) findViewById(R.id.logo); 
    iv.clearAnimation(); 
    iv.startAnimation(anim); 

} 

@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    super.onPause(); 
    ourSong.release(); 
    finish(); 
} 

}

+0

爲用戶提供幫助,並且不要在您的應用中添加啓動畫面。 http://android.cyrilmottier.com/?p=632 – Simon 2013-02-22 22:00:56

+0

這段代碼目前做了什麼,你想做什麼?你會專門縮小你的問題嗎? – halfer 2013-02-22 22:04:25

+0

嗨Halfer,目前的代碼(閃屏)打開到PNG背景和聲音文件。但是,我希望它可以打開大約12個PNG文件(一個接一個地),並給出一個動畫鏡頭的外觀。這似乎很簡單,但我無法讓它工作。任何幫助? – Warren0618 2013-02-22 23:35:42

回答

0

我有13 PNG。圖像,我試圖在我的啓動畫面中一個接一個地運行。

創建一個AnimationDrawable in the form of an <animation-list> drawable resource。列出每個PNG以及XML中應該花費在該幀上的時間。在您的ImageView中使用該AnimationDrawable,並在其上調用startAnimation()以使其開始動畫。

+0

好的傻問題,你如何創建一個AnimationDrawable? – Warren0618 2013-02-22 23:19:30

+0

@ user2100950:如果您點擊答案中的超鏈接,您將看到「AnimationDrawable」文檔,該文檔顯示了用於定義圖片的XML語法,並向您演示如何應用它。請注意,你需要將它應用到ImageView的背景*(這是有原因的,儘管我現在忘記它了)。這裏有'AnimationDrawable'的附加文檔:http://developer.android.com/guide/topics/graphics/drawable-animation.html – CommonsWare 2013-02-22 23:22:47

+0

好吧,我把這段代碼放到我的splash.java super.onCreate(savedInstanceState); \t \t ImageView img =(ImageView)findViewById(R.id.spinning_wheel_image); \t \t img.setBackgroundResource(R.drawable.spin_animation); \t \t AnimationDrawable frameAnimation =(AnimationDrawable)img.getBackground(); \t \t frameAnimation.start(); – Warren0618 2013-02-23 00:19:12