java - 隐藏 ActionBar(定时)和动画 View

标签 java android animation android-actionbar fragment

这基本上是我想要发生的事情:

在散文中:

隐藏ActionBar。然后做一些动画。稍等一下。再次显示 ActionBar

在基本代码中:

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

实际上:

当然,代码的写法,并不是我想要的那样。我尝试了几种解决方案,包括:(1) 使用 Thread.sleep,(2) 创建新的 Runnables,(3) 创建 ActionBar< 的两个实例(一种用于隐藏,一种用于显示),甚至可能还有一些我不再记得的方法。

基本上,到目前为止,结果是 (1) ActionBar 一直显示,(2) 或者整个程序等待,ActionBar 显示,然后播放动画,或 (3) 相同乱序运行的某个版本。

所以我想我的问题是:

如何隐藏 ActionBar,制作一两个动画,然后再次显示? (仅供引用:我在扩展 Fragment 而不是 Activity 的类中运行它。)

最佳答案

使用AnimationListener .在 Animation 结束时,再次显示 ActionBar

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

关于java - 隐藏 ActionBar(定时)和动画 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21949879/

相关文章:

java - System.loadLibrary 卡住,永远不会返回

java - 了解八卦协议(protocol)

java - Android 中 Bitmap 的 getPixels 方法说明

objective-c - iOS 动画 : background continuously moving (game)

java - 让 Maven 项目构建自己的依赖项?

java - 手机号码字段验证

android - HttpClient 在我的 android studio 1.4 中不工作

android - Google Play服务库-android dev:减小库的大小?

css - 卡片翻转在 IE10+ 中不起作用

css - 由于某种原因,SVG 动画有黑色填充