gpt4 book ai didi

android - 原生 actionbar.show() 和 hide() 动画的时长是多少

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:48:40 25 4
gpt4 key购买 nike

我想在操作栏动画时做一些动画。但是,我不知道操作栏动画的持续时间。

最佳答案

不幸的是, native 操作栏动画时间似乎在 Android source code 中进行了硬编码 在 4.1 版之后(没有属性,没有维度,没有方法)并且设置为 250ms:

actionbar.hide()方法在Android 4.1/4.4中的实现示例:

public void doHide(boolean fromSystem) {
if (mCurrentShowAnim != null) {
mCurrentShowAnim.end();
}

if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled
|| fromSystem)) {
mContainerView.setAlpha(1);
mContainerView.setTransitioning(true);
AnimatorSet anim = new AnimatorSet();
float endingY = -mContainerView.getHeight();
if (fromSystem) {
int topLeft[] = {0, 0};
mContainerView.getLocationInWindow(topLeft);
endingY -= topLeft[1];
}
ObjectAnimator a = ObjectAnimator.ofFloat(mContainerView, View.TRANSLATION_Y, endingY);
a.addUpdateListener(mUpdateListener);
AnimatorSet.Builder b = anim.play(a);
if (mContentAnimations && mContentView != null) {
b.with(ObjectAnimator.ofFloat(mContentView, View.TRANSLATION_Y,
0, endingY));
}
if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
mSplitView.setAlpha(1);
b.with(ObjectAnimator.ofFloat(mSplitView, View.TRANSLATION_Y,
mSplitView.getHeight()));
}
anim.setInterpolator(AnimationUtils.loadInterpolator(mContext,
com.android.internal.R.interpolator.accelerate_cubic));
anim.setDuration(250);
anim.addListener(mHideListener);
mCurrentShowAnim = anim;
anim.start();
} else {
mHideListener.onAnimationEnd(null);

这也发生在 Lollipop 上:

public void doHide(boolean fromSystem) {
if (mCurrentShowAnim != null) {
mCurrentShowAnim.end();
}
if (mCurWindowVisibility == View.VISIBLE && (mShowHideAnimationEnabled
|| fromSystem)) {
mContainerView.setAlpha(1);
mContainerView.setTransitioning(true);
AnimatorSet anim = new AnimatorSet();
float endingY = -mContainerView.getHeight();
if (fromSystem) {
int topLeft[] = {0, 0};
mContainerView.getLocationInWindow(topLeft);
endingY -= topLeft[1];
}
ObjectAnimator a = ObjectAnimator.ofFloat(mContainerView, View.TRANSLATION_Y, endingY);
a.addUpdateListener(mUpdateListener);
AnimatorSet.Builder b = anim.play(a);
if (mContentAnimations && mContentView != null) {
b.with(ObjectAnimator.ofFloat(mContentView, View.TRANSLATION_Y,
0, endingY));
}
if (mSplitView != null && mSplitView.getVisibility() == View.VISIBLE) {
mSplitView.setAlpha(1);
b.with(ObjectAnimator.ofFloat(mSplitView, View.TRANSLATION_Y,
mSplitView.getHeight()));
}
anim.setInterpolator(AnimationUtils.loadInterpolator(mContext,
com.android.internal.R.interpolator.accelerate_cubic));
anim.setDuration(250);
anim.addListener(mHideListener);
mCurrentShowAnim = anim;
anim.start();
} else {
mHideListener.onAnimationEnd(null);
}
}

在 4.1 之前(例如 4.0.1) 没有硬编码的持续时间值(实际上根本没有值),无论如何您可以使用反射来访问第一个动画后 Animator 的持续时间。字段访问如下:

private Animator mCurrentShowAnim;

我知道这不是一个完整的答案,但我认为它可能会有帮助。

关于android - 原生 actionbar.show() 和 hide() 动画的时长是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27521232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com