我正在使用android的ImageSwitcher小部件在2张图像之间进行切换,如幻灯片放映,但它仅以动画形式显示,而动画则不显示。有什么问题吗?
代码:
imageSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
@Override
public View makeView() {
RoundedImageView imageView = new RoundedImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setLayoutParams(new
ImageSwitcher.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT));
imageView.setCornerRadius(context.getResources().getDimension(R.dimen.border_radius));
return imageView;
}
});
Animation in,out;
in = AnimationUtils.loadAnimation(context, R.anim.bottom_in);
out = AnimationUtils.loadAnimation(context, R.anim.top_out);
imageSwitcher.setInAnimation(in);
imageSwitcher.setOutAnimation(out);
Glide.with(context)
.asDrawable()
.load(url)
.thumbnail(.1f)
.apply(requestOptions)
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
imageSwitcher.setImageDrawable(resource);
}
});
top_out动画:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromYDelta="0%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="-100%" />
bottom_in动画:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromYDelta="100%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="0%" />
答案 0 :(得分:0)
您的代码中没有发现问题,可能是您的top_out动画出现了问题
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:fromYDelta="0%"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="-100%" />
在android:toYDelta
change it android:toYDelta="-100%" to android:toYDelta="100%"
答案 1 :(得分:0)
我能够通过从Glide请求中删除“ .thumbnail(.1f)”来解决此问题。不了解更深的景象,但是ImageSwitcher现在对我来说很好。 感谢那些以任何方式提供帮助的人。