2013-01-04 93 views
0

我想對4個PNG圖像執行動畫。 我drawable文件夾中res文件夾,包含圖像是動畫和一個animation.xml動畫顯示在android中

現在我的問題是:當我說animation.start 我看不到在模擬器上任何

我的代碼:

package com.androcles.TreeActivity; 

import android.app.Activity; 
import android.graphics.drawable.AnimationDrawable; 
import android.os.Bundle; 
import android.widget.ImageView; 

public class TreeActivity extends Activity { 

private ImageView image1; 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_tree); 
    image1 = (ImageView)findViewById(R.id.imageView1); 
    image1.setImageBitmap(null); 
    image1.setBackgroundResource(R.drawable.animation); 




final AnimationDrawable mailAnimation = (AnimationDrawable) image1.getBackground(); 
image1.post(new Runnable() { 
    public void run() 
    { 
     if (mailAnimation != null) 
     { 
      System.out.println("Before Animation Starts...!!!!!"); 
      mailAnimation.start(); 
      System.out.println("After Animation Starts...!!!!!"); 
     } 
    } 
}); 
} 
} 
+0

此代碼顯示動畫之前開始,動畫開始後,但不顯示動畫 – user1933998

+0

你只是想在圖像視圖時,應用程序開始褪色? –

+0

post animation.xml文件。 – RobinHood

回答

0

試試這個方法:

m_animation = AnimationUtils.loadAnimation(
        getApplicationContext(), R.anim.alpha_animation); 
      m_ivImage.startAnimation(m_animation); 
0

試試用這些代碼。

View view; 
view=(Button)findViewById(R.id.continue_but); // may be image or some thing 


    Animation hyperspaceJump = AnimationUtils.loadAnimation(AppActivity.this, R.anim.slide_left); 
     view.startAnimation(hyperspaceJump); 
     view.setVisibility(View.VISIBLE);