调用FloatingActionButton.hide()与将FloatingActionButton的visiblity设置为Gone相同吗?

时间:2016-07-01 08:07:20

标签: android visibility floating-action-button

只是想澄清一个概念上的怀疑。浮动操作按钮的hide()函数是否类似于visibility.GONE或visibility.INVISIBLE?

1 个答案:

答案 0 :(得分:1)

简而言之:是的。

以下是从设计支持库中获取的ICS(Android SKD 15)函数的实现:

@Override
void hide(@Nullable final InternalVisibilityChangedListener listener, final boolean fromUser) {
    if (mIsHiding || mView.getVisibility() != View.VISIBLE) {
        // A hide animation is in progress, or we're already hidden. Skip the call
        if (listener != null) {
            listener.onHidden();
        }
        return;
    }

    if (!ViewCompat.isLaidOut(mView) || mView.isInEditMode()) {
        // If the view isn't laid out, or we're in the editor, don't run the animation
        mView.internalSetVisibility(View.GONE, fromUser);
        if (listener != null) {
            listener.onHidden();
        }
    } else {
        mView.animate().cancel();
        mView.animate()
                .scaleX(0f)
                .scaleY(0f)
                .alpha(0f)
                .setDuration(SHOW_HIDE_ANIM_DURATION)
                .setInterpolator(AnimationUtils.FAST_OUT_LINEAR_IN_INTERPOLATOR)
                .setListener(new AnimatorListenerAdapter() {
                    private boolean mCancelled;

                    @Override
                    public void onAnimationStart(Animator animation) {
                        mIsHiding = true;
                        mCancelled = false;
                        mView.internalSetVisibility(View.VISIBLE, fromUser);
                    }

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        mIsHiding = false;
                        mCancelled = true;
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        mIsHiding = false;
                        if (!mCancelled) {
                            mView.internalSetVisibility(View.GONE, fromUser);
                            if (listener != null) {
                                listener.onHidden();
                            }
                        }
                    }
                });
    }
}

基本上它只是通过动画改变可见性。