首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Api 21循环显示动画不起作用

Api 21循环显示动画不起作用
EN

Stack Overflow用户
提问于 2014-11-20 22:17:56
回答 2查看 2.8K关注 0票数 4

我不能让循环显示动画工作。我想我检查了最明显的东西:它的开头、宽度和高度都>0,并且它是可见的,没有例外。

我从互联网上加载了一些数据,并将其显示在视图(Fab)中,动画应该只在下载完成后播放。

代码语言:javascript
运行
复制
TmdbHelper helper = new TmdbHelper();
                helper.getMovieById(id, "en", new TmdbHelper.ResultListener() {
                    @Override
                    public void onResultReceived(JSONObject result) {

                        // called when finished downloading

                        try {
                            String rating = result.getString("vote_average");

                            AnimationHelper.circularReveal(fab, 500, 0); 

                            fab.setText(rating);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                });

AnimationHelper:

代码语言:javascript
运行
复制
    public static void circularReveal(final View view, final long duration, long startDelay) {

    // get the center for the clipping circle
    int cx = (view.getLeft() + view.getRight()) / 2;
    int cy = (view.getTop() + view.getBottom()) / 2;

    // get the final radius for the clipping circle
    int finalRadius = Math.max(view.getWidth(), view.getHeight());

    // create the animator for this view (the start radius is zero)
    Animator anim =
            ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);

    anim.setDuration(duration);
    anim.setStartDelay(startDelay);

    anim.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {}
    });

    // make the view visible and start the animation

    anim.start();
}

我在像这样的其他部分中使用圆形显示动画,以确保视图被附加,并且它可以工作:

代码语言:javascript
运行
复制
headerContainer.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

                @Override
                public void onGlobalLayout() {
                    headerContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    AnimationHelper.circularReveal(headerContainer, 500, 200);
                }
            });
EN

Stack Overflow用户

发布于 2014-11-20 23:16:18

也许您应该删除onResultRecieved()中的这一行

代码语言:javascript
运行
复制
fab.setVisibility(View.VISIBLE);

我的假设是,您的循环显示方法工作得很好。这是因为您甚至在动画开始之前就使FAB可见,所以您无法看到它的实际效果。

另外,您所显示的那些正常运行的代码行中没有调用fab.setVisibility(View.VISIBLE)

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27041780

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档