2012-05-16 102 views
0

我对Android有点新,但在VB.net中很流利。我有两个有关初始屏幕的问题:飞溅屏幕的Android Transition图像(TransitionDrawable)

  1. 我正尝试创建启动应用程序启动的启动屏幕。我可以使用Frame-Animations来完成它,但是我想使用TransitionDrawable类,因为它有我想要使用的效果(fadeIn)。在改变定义之后,我对Frame-Animation使用了相同的代码,但无法使其工作。我究竟做错了什么?

  2. 我加载的这个标志由16个图像组成。我如何使用TransitionDrawable类从logo1到logo2到logo3 ...到logo16?我尝试使用一个循环和“imageIds”数组来创建我自己的帧动画,但不能用于Transition。帮助将不胜感激。

这里是我的代码:

public class SplashScreenActivity extends Activity { 

    TransitionDrawable animation; 
    ImageView transImage; 

    Integer[] imageIds = { R.drawable.logo1, R.drawable.logo2, 
      R.drawable.logo3, R.drawable.logo4, R.drawable.logo5, 
      R.drawable.logo6, R.drawable.logo7, R.drawable.logo8, 
      R.drawable.logo9, R.drawable.logo10, R.drawable.logo11, 
      R.drawable.logo12, R.drawable.logo13, R.drawable.logo14, 
      R.drawable.logo15, R.drawable.logo16 }; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
     transImage = (ImageView) findViewById(R.id.splashImageView); 
     animation = (TransitionDrawable) getResources().getDrawable(R.anim.transition_list);  
     transImage.setBackgroundDrawable(animation);   

     transImage.setOnTouchListener(new OnTouchListener() { 
      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       if (event.getAction() == MotionEvent.ACTION_DOWN) { 
        finish(); 
        startActivity(new Intent("com.V1.V1LogoSplash.V1LogoMainActivity")); 
       } 
       return false; 
      }; // END ONTOUCH 
     }); // END ONLISTSENER 
    } 



    @Override 
    public void onWindowFocusChanged(boolean hasFocus) { 
     // TODO Auto-generated method stub 
     super.onWindowFocusChanged(hasFocus); 
     animation.startTransition(3000); 
        finish(); 
    } 

} 

回答

0

您尝试在XML这种类型的代码

public class SplashActivity extends Activity { 

    Thread mSplashThread; 

    private int SPLASH_DISPLAY_LENGTH = 3800; 

    ImageView image; 
    AnimationDrawable frameAnimation; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 

//  this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
//  this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
//    WindowManager.LayoutParams.FLAG_FULLSCREEN); 

     setContentView(R.layout.splashactivity); 

     image = (ImageView) findViewById(R.id.splashImg); 

     image.setBackgroundResource(R.drawable.splash_animation); 

     frameAnimation = (AnimationDrawable) image.getBackground(); 

     Thread splashTread = new Thread() { 
      public void run() { 
       try { 
        sleep(SPLASH_DISPLAY_LENGTH); 
       } catch (InterruptedException e) { 
        e.printStackTrace(); 
       } finally { 
        Intent intent; 
        intent = new Intent(SplashActivity.this, 
          ProductListActivity.class); 
        startActivity(intent); 
        finish(); 
       } 
      } 
     }; 
     splashTread.start(); 
    } 

    @Override 
    public void onWindowFocusChanged(boolean hasFocus) { 
     super.onWindowFocusChanged(hasFocus); 
     frameAnimation.start(); 

    } 

} 

等一个 绘制(把你的IMG在XML)

<?xml version="1.0" encoding="utf-8"?> 
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
    android:oneshot="true" > 

    <item 
     android:drawable="@drawable/survey11" 
     android:duration="500"/> 

    <item 
     android:drawable="@drawable/survey6" 
     android:duration="300"/> 
    <item 
     android:drawable="@drawable/survey5" 
     android:duration="300"/> 

    <item 
     android:drawable="@drawable/survey3" 
     android:duration="300"/> 
    <item 
     android:drawable="@drawable/survey2" 
     android:duration="300"/> 
    <item 
     android:drawable="@drawable/survey1" 
     android:duration="800"/> 



</animation-list> 
+0

谢谢你的信息,但是这使用了框架动画ns,我已经做了。我想使用Transitions。 –