using android animation-list

前端 未结 7 554
鱼传尺愫
鱼传尺愫 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条回答
  •  长发绾君心
    2020-12-28 09:07

    I think the most elegant and versatile option is to extend from the ImageView class:

    public class Loader extends ImageView {
    
        public Loader(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
            init();
        }
    
        public Loader(Context context, AttributeSet attrs) {
            super(context, attrs);
            init();
        }
    
        public Loader(Context context) {
            super(context);
            init();
        }
    
        private void init() {
            setBackgroundResource(R.drawable.loader);
            final AnimationDrawable frameAnimation = (AnimationDrawable) getBackground();
            post(new Runnable(){
                public void run(){
                     frameAnimation.start();
                 }
            });
        }
    }
    

    The loader.xml located in the drawable folder:

    
        
        
        
        
        
        .....
    
    

    Now include in your views something as simple as this:

    
    

提交回复
热议问题