0

我对 Android 有点陌生,但对 VB.net 很流利。我有两个关于启动画面的问题:

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

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

这是我的代码:

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

}
4

1 回答 1

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>
于 2012-05-16T06:39:24.523 回答