今天做一个需求——加载网络图后使控件一直匀速旋转,本来我给控件设置了动画,发现等图片加载出来,控件就不旋转了。后来发现,等得图片加载完后,再启动动画就可以了。
Glide.with(mContext)
.load(url).listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
showAnimation(music_message_music_iv);
return false;
}
})
.into(music_message_music_iv);
//动画
private void showAnimation(View view) {
Animation animation = AnimationUtils.loadAnimation(mContext, R.anim.img_animation);
LinearInterpolator lin = new LinearInterpolator();//设置动画匀速运动
animation.setInterpolator(lin);
view.startAnimation(animation);
}