我Animation scale duration
在 Marshmallow 中阅读 flag 时遇到问题。相同的代码在早期版本的 Marshmallow (6.0.0) 中工作。
我正在使用android.app.Fragment.setCustomTransition()
片段动画的方法。当动画比例持续时间为 0 时developer option settings
,片段不会显示。所以我不得不在这种情况下禁用动画。
我的代码片段:
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;
}
true
问题是:即使动画比例持续时间不是 0,此代码也会在每次调用时返回。
有没有人遇到过这个问题?
编辑1
以下是我使用isAnimationOff()
方法加载片段的代码片段:
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();
}
编辑2
这是具有自定义属性的自定义 LinearLayout:
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();
}
}