2014-12-17 20 views

risposta

6

Purtroppo, il tempo ActionBar animatore nativo sembra essere hard-coded nel Android source code dopo la versione 4.1 (senza attributi, senza dimensioni, esistono metodi) ed è impostato per 250ms :

Esempio di implementaiton di actionbar.hide() metodo in 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); 

Questo accade anche 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); 
     } 
    } 

Prima 4.1 (ad esempio 4.0.1) non esiste alcun valore di durata hardcoded (in realtà non c'è alcun valore), comunque è possibile utilizzare il reflection per accedere alla durata dello Animator dopo la prima animazione. Il campo per l'accesso è il seguente:

private Animator mCurrentShowAnim; 

So che questa non è una risposta completa, ma penso che potrebbe essere utile in ogni caso.

-3

eh @vincentzhou la tua domanda non è ben strutturato ma io cosa questo può darvi qualche guida su come impostare il tempo che si desidera di manipolare voi elemento in JavaScript

$(document).ready(function(){ 
     $('#action').show(); 
     setTimeout(function() { 
     $('#action').fadeOut(); 
    }, 5000); 
    }); 

questo verrà visualizzato l'elemento con id="action" per 5s. spero che possa essere d'aiuto

+0

Mi dispiace, ma penso che sto chiedendo una domanda su Android. – vincentzhou

-3

ActionBar.Show - Mostra l'ActionBar se non è attualmente visualizzato. Non vi è alcuna durata allegata. Rende visibile l'ActionBar finché non viene chiamato actionBar.Hide.

Spero che questo chiarisce

+0

Lo so. Ma quando chiami actionbar.show(), la barra delle azioni verrà mostrata con un'animazione. – vincentzhou

+0

Intendo la durata dell'animazione. – vincentzhou

0

Almeno in 4.3, era 250ms.

vedere la fonte here

+0

Credi? O è questo il vero caso? Per favore riscrivi la tua risposta in modo più concreto. Così com'è, questa risposta sembra un commento. – JAL

Problemi correlati