using android animation-list

前端 未结 7 592
鱼传尺愫
鱼传尺愫 2020-12-28 08:42

I\'m having a little trouble getting an animated loading spinner to work for a splash page. Nothing shows up when I try to run the following code. Any suggestions? It seem

7条回答
  •  猫巷女王i
    2020-12-28 08:53

    Elegant solution - create your own Animated View which will follow life-cycle rules.

    public class AnimatedImageView extends android.support.v7.widget.AppCompatImageView {
        public AnimatedImageView(Context context, AttributeSet attrs) {
            super(context, attrs);
            setImageDrawable(ContextCompat.getDrawable(
                    context, R.drawable.animated_icon));
        }
    
        @Override
        protected void onAttachedToWindow() {
            // It's important to note that the start() method called on 
            // the AnimationDrawable cannot be called during the onCreate() 
            // method of your Activity, because the AnimationDrawable
            // is not yet fully attached to the window.
            super.onAttachedToWindow();
            AnimationDrawable tapAnimation = (AnimationDrawable) getDrawable();
            tapAnimation.start();
        }
    }
    

    here is animated_icon.xml

    
    
        
        
    
    

提交回复
热议问题