2016-04-15 6 views
0

Ich habe Probleme beim Lesen Animation scale duration Flagge in Marshmallow. Derselbe Code funktioniert in einer früheren Version von Marshmallow (6.0.0).Wie zu lesen Animation Skala Dauerflagge in Marshmallow

Ich verwende android.app.Fragment.setCustomTransition() Methode für Fragment-Animation. Wenn die Dauer der Animationsskalierung in developer option settings 0 ist, werden Fragmente nicht angezeigt. Also musste ich die Animation über diese Bedingung deaktivieren.

Mein Code-Schnipsel:

public static boolean isAnimationOff() 
    { 
     final float animatorSpeed; 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) 
     { 
      animatorSpeed = Settings.Global.getFloat(
        context.getContentResolver(), 
        Settings.Global.ANIMATOR_DURATION_SCALE, 
        0); 
     } 
     else 
     { 
      animatorSpeed = Settings.System.getFloat(
        context.getContentResolver(), 
        Settings.System.ANIMATOR_DURATION_SCALE, 
        0); 
     } 
     return animatorSpeed == 0; 
    } 

Das Problem ist: Dieser Code true auf jedem kehrt invoke auch wenn Dauer-Animationsgröße nicht 0

Hat konfrontiert jemand dieses Problem?

Edit1

Im Folgenden finden Sie den Code-Schnipsel, wo ich isAnimationOff() Methode verwenden, um ein Fragment zu laden:

private void loadFragment(Fragment fragment) 
{ 
    FragmentTransaction transaction = getFragmentManager().beginTransaction(); 
    if (!Constants.isAnimationOff()) 
     transaction.setCustomAnimations(animSlideIn, animSlideOut); 
    transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).replace(R.id.frameTopContainer, fragment) 
      .commitAllowingStateLoss(); 
} 

EDIT2

Hier wird die individuelle Linearlayout ist, die benutzerdefinierte Eigenschaft hat:

public class FractionLinearLayout extends LinearLayout 
{ 

    DisplayMetrics matrics = getContext().getResources().getDisplayMetrics(); 

    public FractionLinearLayout(Context context, AttributeSet attrs, 
           int defStyleAttr) 
    { 
     super(context, attrs, defStyleAttr); 
     // TODO Auto-generated constructor stub 
    } 

    public FractionLinearLayout(Context context) 
    { 
     super(context); 
     // TODO Auto-generated constructor stub 

    } 

    public FractionLinearLayout(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
     // TODO Auto-generated constructor stub 
    } 

    public float getFractionTranslationX() 
    { 

     return getWidth() > 0 ? super.getTranslationX()/getWidth() : Float.MAX_VALUE; 
    } 

    public void setFractionTranslationX(float translationX) 
    { 

     int width = getWidth(); 
     super.setTranslationX(width > 0 ? width * translationX : Float.MAX_VALUE); 
    } 

    public float getFractionTranslationY() 
    { 

     return getHeight() > 0 ? super.getTranslationX()/getHeight() : Float.MAX_VALUE; 
    } 

    public void setFractionTranslationY(float translationY) 
    { 
     int height = getHeight(); 
     super.setTranslationY(height > 0 ? height * translationY : Float.MAX_VALUE); 
    } 

    public float getAnimWidth() 
    { 

     return getLayoutParams().width; 
    } 

    public void setAnimWidth(int animWidth) 
    { 

     getLayoutParams().width = animWidth; 
     requestLayout(); 
    } 
} 
+0

Was benötigen Sie eigentlich 'isAnimationOff' Methode für? – pskink

+0

Ich überprüfe, ob die Animationsskala 0 ist (die Animation ist aus den Einstellungen der Entwickleroptionen ausgeschalten). wenn kein 'setCustomTransition()' aufgerufen wird, wird sonst nicht aufgerufen. – chandil03

+0

@pskink irgendein Glück. – chandil03

Antwort

0

Ich hatte ein Problem in meiner FractionLinearLayout Klasse. In der setFractionTranslationX() Methode gab getWidth() beim ersten Aufruf 0 zurück. Das führte dazu, dass mein Code verhinderte, dass Fragment angezeigt wird, wenn die Animation ausgeschaltet ist. Jetzt habe ich getWidth() Linie mit getResources().getDisplayMetrics().widthPixels ersetzt und alles funktioniert gut.

Aktualisiert Code:

public class FractionLinearLayout extends LinearLayout 
{ 

    DisplayMetrics matrics = getContext().getResources().getDisplayMetrics(); 

    public FractionLinearLayout(Context context, AttributeSet attrs, 
           int defStyleAttr) 
    { 
     super(context, attrs, defStyleAttr); 
     // TODO Auto-generated constructor stub 
    } 

    public FractionLinearLayout(Context context) 
    { 
     super(context); 
     // TODO Auto-generated constructor stub 

    } 

    public FractionLinearLayout(Context context, AttributeSet attrs) 
    { 
     super(context, attrs); 
     // TODO Auto-generated constructor stub 
    } 

    public float getFractionTranslationX() 
    { 

     return getWidth() > 0 ? super.getTranslationX()/getWidth() : 0; 
    } 

    public void setFractionTranslationX(float translationX) 
    { 
     int width = getResources().getDisplayMetrics().widthPixels; 
     super.setTranslationX(width > 0 ? width * translationX : 0); 
    } 

    public float getFractionTranslationY() 
    { 

     return getHeight() > 0 ? super.getTranslationY()/getHeight() : 0; 
    } 

    public void setFractionTranslationY(float translationY) 
    { 
     int height = getResources().getDisplayMetrics().heightPixels; 
     super.setTranslationY(height > 0 ? height * translationY : 0); 
    } 

    public float getAnimWidth() 
    { 

     return getLayoutParams().width; 
    } 

    public void setAnimWidth(int animWidth) 
    { 

     getLayoutParams().width = animWidth; 
     requestLayout(); 
    } 
} 

aber immer noch kann ich nicht Knowl, warum ist ANIMATOR_DURATION_SCALE Flagge nicht in Eibisch arbeiten.