【问题标题】:How to animate videoView along with the imageView and recyclerView?如何将 videoView 与 imageView 和 recyclerView 一起制作动画?
【发布时间】:2016-12-21 03:57:31
【问题描述】:

我想在 imageView 和 recyclerView 上方的 videoView 上使用动画。起初,videoView 的可见性消失了,当我单击 recyclerView 上的项目时,我想让 videoView 可见,动画向下滑动,并且还使用 imageView 的动画来滑动并使其消失。我怎样才能做到这一点。我已经给出了布局前后的快照。

动画前:

动画之后:

【问题讨论】:

    标签: android animation android-recyclerview android-videoview


    【解决方案1】:

    这是我为类似情况所做的。在您的布局中,您需要将两个视图放在另一个之上(在它们必须出现的确切位置)。在 onCreate 中将全局布局侦听器添加到 videoView / imageView 一次,然后只需更改相应视图的可见性。此代码可以与 imageView 一起重用,但请记住,您不能同时更改两个视图的可见性,因为它们会重叠。也许您需要等待第一个动画开始播放,然后再显示下一个。这取决于你。

    private static final int ANIMATION_DURATION = 350;
    
    private void addVideoViewAnimation(final View videoView) {
        videoView.setTag(videoView.getVisibility());
        videoView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                int newVisibility = videoView.getVisibility();
                if ((int) videoView.getTag() != newVisibility) {
                    videoView.setTag(newVisibility);
    
                    TranslateAnimation animation;
                    if (newVisibility == View.VISIBLE) {
                        animation = new TranslateAnimation(0, 0, -videoView.getHeight(), 0);
                        animation.setInterpolator(new DecelerateInterpolator());
                    } else {
                        animation = new TranslateAnimation(0, 0, 0, -videoView.getHeight());
                        animation.setInterpolator(new AccelerateInterpolator());
                    }
                    animation.setDuration(ANIMATION_DURATION);
                    videoView.startAnimation(animation);
                }
            }
        });
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多