我想在安卓系统中用眨眼动画更改图像,图像是用Glide直接从服务器加载的.或者有其他选择吗



当动画闪烁时,我想在这里更改图像。我不能在其中设置多个图像,我是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();
}
}

检查这是否有帮助。

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