6428


現在ボタンを押すとアニメーションが表示されるようなプログラムを組んでいるのですが、ボタンを押してからアニメーションが表示されるまでの間に時間があり、スムーズにアニメーションが表示されません。ログを見てみると、`Skipped
108 frames! The application may be doing too much work on its main thread.`
や、`GC_FOR_ALLOC freed <1K, 1% free 23795K/23900K, paused 10ms, total 10ms`
などと表示されています。アニメーションの際の各画像サイズが大きすぎるのだと思うのですが、色々と調べて画像サイズを減らそうとしてみても、画像が荒くなったりと中々思うようにいきません。解決策としてはどういった選択肢をとればよいでしょうか？下記にコードを記します。すみませんが、宜しくお願いします。

[code]

    public class AnimationActivity extends Activity {
        private Activity mActivity = this;
        ImageView animationImageView;
        AnimationConfig animationConfig;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_animation);
    
            animationImageView = (ImageView) findViewById(R.id.animation_imageview);
    
            animationConfig = new AnimationConfig(mActivity, animationImageView, 2000, 2000, 50);
            animationConfig.setAnimationFrame(R.drawable.slot_01);
            animationConfig.setAnimationFrame(R.drawable.slot_02);
            animationConfig.setAnimationFrame(R.drawable.slot_03);
            animationConfig.setAnimationFrame(R.drawable.slot_04);
            animationConfig.setAnimationFrame(R.drawable.slot_05);
            animationConfig.setAnimationFrame(R.drawable.slot_06);
            animationConfig.setAnimationFrame(R.drawable.slot_07);
            animationConfig.setAnimationFrame(R.drawable.slot_08);
            animationConfig.setAnimationFrame(R.drawable.slot_09);
            animationConfig.setAnimationFrame(R.drawable.slot_10);
            animationConfig.setAnimationFrame(R.drawable.slot_11);
            animationConfig.setAnimationFrame(R.drawable.slot_12);
            animationConfig.setAnimationFrame(R.drawable.slot_13);
            animationConfig.setAnimationFrame(R.drawable.slot_14);
            animationConfig.setAnimationFrame(R.drawable.slot_15);
            animationConfig.setAnimationFrame(R.drawable.slot_16);
            animationConfig.setAnimationFrame(R.drawable.slot_17);
            animationConfig.setAnimationFrame(R.drawable.slot_18);
    
            animationConfig.startAnimation();
        }
    }
    
    public class AnimationConfig {
        private Activity mActivity;
        private int mDuration;
        private int mOffset;
        private int mEachImageShowTime;
        private AnimationSet mAnimationSet;
        private ImageView mAnimationImageView;
        private AnimationDrawable anim;
        private List<Drawable> mFrameList = new ArrayList<Drawable>();
    
        public AnimationConfig(Activity activity, ImageView imageView, int duration, int offset, int eachImageShowTime) {
            mActivity = activity;
            mAnimationImageView = imageView;
            mDuration = duration;
            mOffset = offset;
            mEachImageShowTime = eachImageShowTime;
        }
    
        public void setAnimationFrame(int image) {
            mFrameList.add(mActivity.getResources().getDrawable(image));
        }
    
        public void startAnimation() {
            setFrameAnimation(mAnimationImageView, mEachImageShowTime);
            mAnimationImageView.post(new Runnable() {
                @Override
                public void run() {
                    anim.start();
                }
            });
            mAnimationImageView.startAnimation(setFadeAnimation(mDuration, mOffset));
        }
    
        public void setFrameAnimation(ImageView imageView, int sec) {
            mAnimationImageView = imageView;
            anim = new AnimationDrawable();
            for (Drawable frame:mFrameList) { anim.addFrame(frame, sec); }
            anim.setOneShot(false);
            imageView.setImageDrawable(anim);
        }
    
        public AnimationSet setFadeAnimation(int duration, final int offset){
            AlphaAnimation fadeIn = new AlphaAnimation(0, 1);
            final AlphaAnimation fadeOut = new AlphaAnimation(1, 0);
            fadeIn.setDuration(duration);
    
            fadeIn.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    fadeOut.setStartOffset(offset);
                }
    
                @Override
                public void onAnimationEnd(Animation animation) {
    
                }
    
                @Override
                public void onAnimationRepeat(Animation animation) {
    
                }
            });
    
            fadeOut.setDuration(duration);
            fadeOut.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
    
                }
    
                @Override
                public void onAnimationEnd(Animation animation) {
                    mAnimationImageView.setVisibility(View.GONE);
                    mAnimationSet.setFillAfter(true);
                    mActivity.finish();
                }
    
                @Override
                public void onAnimationRepeat(Animation animation) {
    
                }
            });
    
            mAnimationSet = new android.view.animation.AnimationSet(false); {
                mAnimationSet.addAnimation(fadeIn);
                mAnimationSet.addAnimation(fadeOut);
            }
    
            return mAnimationSet;
        }
    }
    
[/code]


CC BY-SA 3.0
2015-02-12T04:42:40.780
6360
2015-02-13T04:44:10.833
5210
question
android android-animation
Skipped 108 frames! The application may be doing too much work on its main thread


<https://tinypng.com/> で画像のサイズを圧縮してみてはいかがでしょうか？  
画像が荒くなることもないかと思います。


CC BY-SA 3.0
2015-02-13T04:44:10.833
6428
2015-02-13T04:44:10.833
3488
6360
answer