ViewFlipper有"巨大"的延迟

Thy*_*hys 8 animation android

我有一个ViewFlipper,它在调用showPrevious时运行一个视图动画.动画效果很好.但问题是它开始延迟超过1秒.现在这似乎并不多,但它严重延迟了应用程序的使用.

我的动画看起来像这样;

Animation inFromLeft = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, -1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
inFromLeft.setDuration(350);
inFromLeft.setInterpolator(new LinearInterpolator());   

Animation outtoRight = new TranslateAnimation(
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, +1.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f,
    Animation.RELATIVE_TO_PARENT, 0.0f);
outtoRight.setDuration(350);
outtoRight.setInterpolator(new LinearInterpolator());
Run Code Online (Sandbox Code Playgroud)

我使用setInAnimation和设置动画setOutAnimation;

setInAnimation(inFromLeft);
setOutAnimation(outtoRight);
Run Code Online (Sandbox Code Playgroud)

然后我就用启动动画 showPrevious

动画的延迟超过1秒是否有任何原因,动画的startTime为-1,startOffset为0.

Spa*_*rky 2

两个建议。首先,如果可能的话,改用 ViewPager。其次,如果第一种方法不可能,则使用基于 XML 的动画。将内容从代码中推出并放入资源中通常是一种胜利。