我想在动作栏动画时做一些动画。但是,我不知道动作栏动画的持续时间。
答案 0 :(得分:6)
不幸的是,本机操作栏动画时间似乎在版本4.1之后的Android source code 中进行了硬编码(没有属性,没有维度,没有方法),而且它是' s设置为 250ms :
Android 4.1 / 4.4中actionbar.hide()
方法的实现示例:
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
&#39 ;第一个动画后的持续时间。要访问的字段如下:
private Animator mCurrentShowAnim;
我知道这不是一个完整的答案,但我认为无论如何它可能会有所帮助。
答案 1 :(得分:0)
至少在4.3,这是250毫秒。
查看来源here
答案 2 :(得分:-3)
嗯@vincentzhou你的问题结构不合理,但我可以为你提供一些关于如何设置你希望你在JavaScript中操作元素的时间的指导
$(document).ready(function(){
$('#action').show();
setTimeout(function() {
$('#action').fadeOut();
}, 5000);
});
这将显示带有id="action"
的元素5秒。希望它可以帮助
答案 3 :(得分:-3)
ActionBar.Show - 显示当前未显示的ActionBar。没有持续时间。它使ActionBar可见,直到调用actionBar.Hide。
希望这澄清