Циклический просмотр растровых изображений для ImageView - PullRequest
0 голосов
/ 12 марта 2019

С помощью Flask в python я отправил несколько изображений в приложение для Android и сохранил их в ArrayList of Bitmaps

Как я могу автоматически прокручивать их в анимации постепенного исчезновения / постепенного исчезновения в бесконечном цикле?

1 Ответ

1 голос
/ 13 марта 2019

Да, вы можете сделать, как показано ниже: (здесь для демонстрации я взял массив для рисования. Вы можете использовать вместо этого ваш растровый массив или использовать его для демонстрации.)

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) {
        }
    });

}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...