代码之家  ›  专栏  ›  技术社区  ›  Usman Rana

ImageSwitcher未显示动画

  •  0
  • Usman Rana  · 技术社区  · 6 年前

    我使用android的ImageSwitcher小部件在两个图像之间切换,就像幻灯片放映一样,但它只在动画中显示,而在动画中不显示。问题是什么?

    代码:

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

    顶出动画:

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

    动画中的底部按钮:

    <?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%" />
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   Ashvin solanki    6 年前

    在你的代码中找不到问题可能是问题在你的顶级动画中

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

    在安卓:toYDelta

    change it android:toYDelta="-100%" to android:toYDelta="100%"
    
        2
  •  0
  •   Usman Rana    6 年前

    我可以通过从Glide请求中删除“.thumbnail(.1f)”来解决此问题。不知道更深的视野,但图像切换器的工作很好,我现在。 感谢那些不择手段帮助过我的人。

    推荐文章