ImageSwitcher is not showing outAnimation

爷,独闯天下 提交于 2019-12-24 19:45:11

问题


I'm using ImageSwitcher widget of android to transition between 2 images like a slide show but it is showing only in animation and out animation is not showing. What is the issue?

Code:

 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 animation:

<?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 animation:

<?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%" />

回答1:


No Problem found in Your Code May be Problem Is in Your top_out animation

<?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%" />

In android:toYDelta

change it android:toYDelta="-100%" to android:toYDelta="100%"



回答2:


I was able to resolve the issue by removing '.thumbnail(.1f)' from the Glide request. Don't know the deeper sight but ImageSwitcher is working fine for me now. Thanks to fellows who helped by any means.



来源:https://stackoverflow.com/questions/52346477/imageswitcher-is-not-showing-outanimation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!