Create animated splash screen using frames on Android

后端 未结 3 1247
逝去的感伤
逝去的感伤 2020-12-19 19:20

So here\'s the deal, I\'ve searched every single question and link online but none are helpful. I have 120 frames of an animation in .jpg format for my splash screen. I unde

相关标签:
3条回答
  • 2020-12-19 19:35

    You can try to do it without AnimationDrawable using Handler.postDelayed. Something like this:

    final ImageView image = (ImageView) findViewById(R.id.SplashImageView);
    final Handler handler = new Handler();
    
    final Runnable animation = new Runnable() {
        private static final int MAX = 120;
        private static final int DELAY = 50;
    
        private int current = 0;
    
        @Override
        public void run() {
            final Resources resources = getResources();
            final int id = resources.getIdentifier("l" + current, "drawable", getPackageName());
            final Drawable drawable = resources.getDrawable(id);
    
            image.setBackgroundDrawable(drawable);
            handler.postDelayed(this, DELAY);
            current = (current + 1) % MAX;
        }
    };
    
    handler.post(animation);
    

    This solution requires less memory because it keeps only one drawable at the time.

    You can cancel the animation using handler.removeCallbacks(animation);.

    If you want make a one-shot animation you can call handler.postDelayed conditionally:

    if (current != MAX - 1) {
        handler.postDelayed(this, DELAY);
    }
    
    0 讨论(0)
  • 2020-12-19 19:39

    Y̶o̶u̶ ̶n̶e̶e̶d̶ ̶t̶o̶ ̶c̶a̶l̶l̶ ̶.̶r̶e̶c̶y̶c̶l̶e̶(̶)̶ ̶o̶n̶ ̶t̶h̶e̶ ̶b̶i̶t̶m̶a̶p̶s̶ ̶y̶o̶u̶ ̶d̶o̶n̶'̶t̶ ̶u̶s̶e̶ ̶a̶n̶y̶m̶o̶r̶e̶.̶ ̶O̶t̶h̶e̶r̶w̶i̶s̶e̶ ̶t̶h̶e̶y̶ ̶w̶o̶n̶t̶ ̶b̶e̶ ̶g̶a̶r̶b̶a̶g̶e̶ ̶c̶o̶l̶l̶e̶c̶t̶e̶d̶ ̶p̶r̶o̶p̶e̶r̶l̶y̶.̶

    Also in the manifest set uses large heap to true. This gives you a bit more space to breathe. >)

    0 讨论(0)
  • 2020-12-19 19:46

    i tried all of those solution with each one getting better :D i could use more frame and more resolution but still not satisfying to managers :( i found best solution is to use video instead of frames it works like a charm for even low memory devices i tested 150 frames each of size 480*854 with a video codec (H.264 mp4) on xperia u with 256mb of ram

    0 讨论(0)
提交回复
热议问题