这是我想在动画闪烁时更改图像的地方。我无法在其中设置多个图像,我是 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);
关于java - 我想在 android 中使用闪烁动画更改图像,并且图像是使用 Glide 直接从服务器加载的。或任何其他选择来做到这一点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60726348/