Я хочу изменить изображение с анимацией мигания в android, и изображения загружаются напрямую с сервера с Glide. или любой другой вариант сделать это? - PullRequest
0 голосов
/ 17 марта 2020

Здесь я хочу изменить изображение, когда анимация мигает. Я не могу установить более одного изображения в нем, я новичок в разработке Android.

введите описание изображения здесь

public class MainActivity extends AppCompatActivity {

    RelativeLayout suggestion;
    CircleImageView suggestionImage;
    AnimationDrawable animation;
    BitmapDrawable frame;

    String[] imageUrl = new String[]{"https://i.picsum.photos/id/663/200/200.jpg", "https://i.picsum.photos/id/1026/200/200.jpg", "https://i.picsum.photos/id/1037/200/200.jpg"};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        suggestion = (RelativeLayout) findViewById(R.id.suggestionContainer);
        suggestionImage = (CircleImageView) findViewById(R.id.suggestionImage);

        final Animation moveOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move_out);
        final Animation blink = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
        moveOut.setFillAfter(true);

        final Handler slide = new Handler();
        slide.postDelayed(new Runnable() {
            @Override
            public void run() {

                suggestion.startAnimation(moveOut);
            }
        }, 2100);

        suggestion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(),"touched", Toast.LENGTH_SHORT).show();
            }
        });

            Glide.with(this)
                    .asBitmap()
                    .load(imageUrl[1])
                    .into(new CustomTarget<Bitmap>() {
                        @Override
                        public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {

                            frame = new BitmapDrawable(resource);

                            animation.addFrame(frame, 1000);
                        }
                        @Override
                        public void onLoadCleared(@Nullable Drawable placeholder) {
                        }
                    });


        animation = new AnimationDrawable();

        animation.setOneShot(true);

        suggestionImage.setBackgroundDrawable(animation);
        suggestionImage.startAnimation(blink);
        animation.start();
    }

}

1 Ответ

0 голосов
/ 17 марта 2020

проверьте, может ли это помочь.

image = (ImageView) findViewById(R.id.image);
    Animation animation = new AlphaAnimation((float) 0.5, 0); // Change alpha from fully visible to invisible
    animation.setDuration(500); // duration - half a second
    animation.setInterpolator(new LinearInterpolator()); // do not alter
                                                         // animation
                                                         // rate
    animation.setRepeatCount(Animation.INFINITE); // Repeat animation
                                                  // infinitely
    animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the
                                                // end so the button will
                                                // fade back in
    image.startAnimation(animation);
...