簡體   English   中英

用於啟動畫面的Android過渡圖像(TransitionDrawable)

[英]Android Transition Images (TransitionDrawable) for Splash Screen

我對Android有點陌生,但是在VB.net上非常流利。 關於啟動畫面,我有兩個問題:

  1. 我正在嘗試創建在應用程序啟動時啟動的啟動屏幕。 我可以使用Frame-Animations來做到這一點,但由於我想使用它具有(fadeIn)的效果,因此想使用TransitionDrawable類。 更改定義后,我對幀動畫使用了相同的代碼,但無法使其正常工作。 我究竟做錯了什么?

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

}

您嘗試此類型代碼

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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM