【发布时间】:2015-04-30 02:07:26
【问题描述】:
这是一个奇怪的问题。我有一个动画,将视图翻转 90 度,然后将另一个视图旋转另外 90 度,从而允许更改图像。这很有效,并且在三星 Tab 3 上运行良好;但是在 Tab 4 上,动画非常生涩。如果我打开“Profile GPU 渲染”-“在屏幕上显示为条形”,动画会变得非常流畅。
我已经在动画中添加了调试日志,我发现 applyTransformation 函数被调用的次数是相同的,当它是生涩的和平滑的时候。所以我可以把它归结为屏幕没有被足够刷新。任何想法都会很棒。
这里是翻转动画。 公共类 AnimatedFlip 扩展了动画 { 私人最终浮动 mFromDegrees; 私人最终浮动 mToDegrees; 私人最终浮动 mCenterX; 私人最终浮动 mCenterY; 私人相机 mCamera;
public AnimatedFlip(float aFromDegrees, float aToDegrees, float aCenterX, float aCenterY)
{
mFromDegrees = aFromDegrees;
mToDegrees = aToDegrees;
mCenterX = aCenterX;
mCenterY = aCenterY;
}
@Override
public void initialize(int aWidth, int aHeight, int aParentWidth, int aParentHeight)
{
super.initialize(aWidth, aHeight, aParentWidth, aParentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float aInterpolatedTime, Transformation aTransformation)
{
float degrees = mFromDegrees + ((mToDegrees - mFromDegrees) * aInterpolatedTime);
final Matrix matrix = aTransformation.getMatrix();
mCamera.save();
mCamera.rotateY(degrees);
mCamera.getMatrix(matrix);
mCamera.restore();
matrix.preTranslate(-mCenterX, -mCenterY);
matrix.postTranslate(mCenterX, mCenterY);
}
}
动画从这个调用开始。
mFlipStartingView.setVisibility(View.VISIBLE);
applyRotation(0, 90, mFlipStartingView);
这是执行动画的函数。
private void applyRotation(float aStart, float aEnd, final ImageView aView)
{
// Find the center of image
float centerX = aView.getWidth() / 2.0f + aView.getX();
float centerY = aView.getHeight() / 2.0f + aView.getY();
// Create a new 3D rotation with the supplied parameter
// The animation listener is used to trigger the next animation
final AnimatedFlip rotation = new AnimatedFlip(aStart, aEnd, centerX, centerY);
rotation.setDuration(mFlipAnimationTime);
rotation.setFillAfter(false);
rotation.setInterpolator(new LinearInterpolator());
rotation.setAnimationListener(new Animation.AnimationListener()
{
@Override public void onAnimationStart(Animation animation)
{
}
@Override public void onAnimationEnd(Animation animation)
{
if (aView != mFlipView)
{
mFlipStartingView.setVisibility(View.INVISIBLE);
mFlipView.setVisibility(View.VISIBLE);
applyRotation(-89, 0, mFlipView);
}
}
@Override public void onAnimationRepeat(Animation animation)
{
}
});
aView.startAnimation(rotation);
}
【问题讨论】: