当前位置: 首页 > 工具软件 > Android Angle > 使用案例 >

android toggle

任飞鸣
2023-12-01

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


 类似资料:

相关阅读

相关文章

相关问答