Да, вы можете сделать, как показано ниже: (здесь для демонстрации я взял массив для рисования. Вы можете использовать вместо этого ваш растровый массив или использовать его для демонстрации.)
public class Main3Activity extends AppCompatActivity {
private ImageView imageView;
private int imageArray[] = { R.drawable.ic_launcher_background, R.drawable.ic_launcher_background,R.drawable.ic_launcher_background };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
imageView = (ImageView) findViewById(R.id.imageView);
startAnimation();
}
private void startAnimation() {
int fadeInDuration = 500;
int timeBetween = 3000;
int fadeOutDuration = 1000;
int random = new Random().nextInt((imageArray.length - 1) + 1);
imageView.setVisibility(View.INVISIBLE);
imageView.setImageResource(imageArray[random]);
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator());
fadeIn.setDuration(fadeInDuration);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setStartOffset(fadeInDuration + timeBetween);
fadeOut.setDuration(fadeOutDuration);
AnimationSet animation = new AnimationSet(false);
animation.addAnimation(fadeIn);
animation.addAnimation(fadeOut);
animation.setRepeatCount(1);
imageView.setAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationEnd(Animation animation) {
startAnimation();
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
});
}
}