隐藏动作条(定时)和动画视图视图、动作、动画

2023-09-12 22:02:19 作者:不解的迷惘ミ↙

下面基本上是我希望发生的:

Here is basically what I want to happen:

散文:

隐藏动作条。然后做一些动画(S)。等待一点点。展会动作条了。

Hide ActionBar. Then do some animation(s). Wait a little bit. Show ActionBar again.

在基本code:

ActionBar actionBar = getActivity().getActionBar();
actionBar.hide();

TextView someTextView = (TextView) rootView.findViewById(R.id.some_textview);
Animation a = AnimationUtils.loadAnimation(getActivity(), android.R.anim.slide_in_left);
int duration = 1000;
a.setDuration(duration);
someTextView.startAnimation(a);

wait(duration);

actionBar.show();

在现实中:

当然,code被写入的方式,它不工作,我多么希望。我试了几种解决方案,其中包括:(1)使用视频下载,(2)建立新的的Runnable , (3)创建动作条的两个实例(一个用于隐藏和一个用于显示),甚至可能多了一些方法,我不记得了。

Of course, the way the code is written, it doesn't work how I want. I've tried several solutions, including: (1) using Thread.sleep, (2) creating new Runnables, (3) creating two instances of ActionBar (one for hiding and one for showing), and maybe even a few more methods that I don't recall anymore.

基本上,到目前为止,所发生的情况,结果已经或者(1)的动作条终止所示的整个时间,(2)或整个程序等待,在动作条显示,然后播放动画,或者(3)某些版本的相同外的顺序运行。

Basically, so far, what has happened as a result has been either (1) the ActionBar is shown the entire time, (2) or the whole program waits, the ActionBar is shown, then the animation plays, or (3) some version of the same out-of-order run.

所以我想我的问题是:

我如何隐藏动作条,做一个动画或两个,然后再次显示它? (供参考:我在扩展的类运行这样的片段,而不是活动

How do I hide the ActionBar, do an animation or two, then show it again? (FYI: I'm running this in a class that extends a Fragment, not an Activity.)

推荐答案

使用 AnimationListener 。在年底的动画,显示动作条了。

use AnimationListener. At the end of the Animation, show ActionBar again.

    animation.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
            // You can hide ActionBar here
            getActivity().getActionBar().hide();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // getActivity().getActionBar().show();
            // and according to you, use Handler
            new Handler().postDelayed(new Runnable() {

                @Override
                public void run() {
                    getActivity().getActionBar().show();
                }
            }, 3 * 1000);
        }
    });
    someTextView.startAnimation(animation);