启动画面的Android过渡图像(TransitionDrawable)

时间:2012-05-16 06:33:54

标签: android transitions transitiondrawable

我对Android有点新鲜,但对VB.net非常流利。我有两个关于启动画面的问题:

  1. 我正在尝试创建一个在应用程序启动时启动的启动画面。我可以使用Frame-Animations进行,但是想使用TransitionDrawable类,因为它具有我想要使用的效果(fadeIn)。在更改定义后,我对Frame-Animation使用了相同的代码,但无法使其工作。我做错了什么?

  2. 我要加载的这个徽标包含16张图片。如何使用TransitionDrawable类从logo1到logo2到logo3 ...再到logo16?我尝试使用循环和“imageIds”数组来创建我自己的帧动画,但它不能用于转换。非常感谢帮助。

  3. 这是我的代码:

    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();
        }
    
    }
    

1 个答案:

答案 0 :(得分:0)

您尝试此类型代码

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();

    }

}

和另一个 可绘制的xml(你的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>