Android 动画:隐藏/显示菜单 [英] Android Animation: Hide/Show Menu

查看:22
本文介绍了Android 动画:隐藏/显示菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的应用添加动画,该动画将在单击时隐藏或显示菜单.基本上类似于脉冲新闻阅读器文章视图.我能够为菜单容器设置动画.但是,菜单不会在主容器为菜单支架创建空间的同时向下滑动.我想知道如何解决这个问题.

I am trying to add an animation to my app that will hide or show a menu on single tap. Basically something similar to Pulse news readers article view. I am able to animate the menu container. However,the menu does not slide down at the same time as the main container is creating space for the menu holder. I would like to know how to fix this issue.

这是我的动画代码:

if(homeTabBar.getVisibility() == View.GONE){
    homeTabBar.setVisibility(View.VISIBLE);
    final Animation tabBlockHolderAnimation = AnimationUtils.loadAnimation(ArticleActivity.this, R.anim.tab_down);

    tabBlockHolderAnimation.setFillAfter(true);
    homeTabBar.startAnimation(tabBlockHolderAnimation);


}else{

    final Animation tabBlockHolderAnimation = AnimationUtils.loadAnimation(ArticleActivity.this, R.anim.tab_up);
    tabBlockHolderAnimation.setAnimationListener(new AnimationListener(){



    @Override
    public void onAnimationEnd(Animation animation) {

    // TODO Auto-generated method stub

    homeTabBar.setVisibility(View.GONE);
   }
});

tabBlockHolderAnimation.setFillAfter(true);

homeTabBar.startAnimation(tabBlockHolderAnimation);

推荐答案

public void toggle() {
    TranslateAnimation anim = null;

    isOpen = !isOpen;

    if (isOpen) {
        layoutRoot.setVisibility(View.VISIBLE);
        anim = new TranslateAnimation(0.0f, 0.0f, layoutRoot.getHeight(), 0.0f);
    } else {
        anim = new TranslateAnimation(0.0f, 0.0f, 0.0f, layoutRoot.getHeight());
        anim.setAnimationListener(collapseListener);
    }

    anim.setDuration(300);
    anim.setInterpolator(new AccelerateInterpolator(1.0f));
    layoutRoot.startAnimation(anim);
}

Animation.AnimationListener collapseListener = new Animation.AnimationListener() {
    public void onAnimationEnd(Animation animation) {
        layoutRoot.setVisibility(View.GONE);
    }

    @Override
    public void onAnimationRepeat(Animation animation) {
    }

    @Override
    public void onAnimationStart(Animation animation) {
    }
};

这篇关于Android 动画:隐藏/显示菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆