端末によってアニメーションが動かない
現在drawable-hdpi
、drawable-xhdpi
、drawable-xxhdpi
フォルダにそれぞれサイズの異なる画像を置いています。そしてアニメーションを行うのですが、なぜかxxhdpi
の端末のみアニメーションが動作し、xhdpi
の端末は一枚画像が表示されるだけで、hdpi
の端末に至っては画像すら表示されません。なぜなのでしょうか?下記にコードを記します。すみませんが、どなたか分かる方がいればよろしくお願いします。
MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); setContentView(R.layout.activity_animation);
animationImageView = (ImageView)findViewById(R.id.animation_imageview);
animationImageView.post(new Runnable() {
@Override
public void run() {
if (getIntent().getStringExtra("animType").equals("normal_animation")) {
AnimationConfig animationConfig = new AnimationConfig(activity, activity);
animationConfig.setAnimationData(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.startAnimation();
}
}
});
}
AnimationConfig
public class AnimationConfig {
private Activity mActivity;
private Context mContext;
private int mDuration;
private int mOffset;
private int mEachImageShowTime;
private AnimationSet mAnimationSet;
private ImageView mAnimationImageView;
private List<Drawable> mFrameList = new ArrayList<Drawable>();
public AnimationConfig(Activity activity, Context context) {
mActivity = activity;
mContext = context;
}
public void setAnimationFrame(int image) {
mFrameList.add(mContext.getResources().getDrawable(image));
}
public void setAnimationData(ImageView imageView, int duration, int offset, int eachImageShowTime) {
mAnimationImageView = imageView;
mDuration = duration;
mOffset = offset;
mEachImageShowTime = eachImageShowTime;
}
public void startAnimation() {
setFrameAnimation(mAnimationImageView, mEachImageShowTime);
mAnimationImageView.startAnimation(setFadeAnimation(mDuration, mOffset));
}
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);
screenTransition();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mAnimationSet = new android.view.animation.AnimationSet(false); {
mAnimationSet.addAnimation(fadeIn);
mAnimationSet.addAnimation(fadeOut);
}
return mAnimationSet;
}
public void setFrameAnimation(ImageView imageView, int sec) {
mAnimationImageView = imageView;
AnimationDrawable anim = new AnimationDrawable();
for (Drawable frame:mFrameList) {
anim.addFrame(frame, sec);
}
anim.setOneShot(false);
imageView.setImageDrawable(anim);
}
}