Android viewflipper 动画滞后

标签 android animation transition viewflipper lag

我有一些基本的动画,当它们用于 Activity 之间的转换时,它们就像一个魅力。

问题是,当我在我的取景器上使用它们时,我看到了非常明显的延迟。 这是我的 Activity 中的代码 fragment :

 private void initUI(){
    layoutInflater = LayoutInflater.from(this);
    flipViewMain = layoutInflater.inflate(R.layout.flip_view_profile_main, null);
    flipListHolder = layoutInflater.inflate(R.layout.flip_view_profile_list, null);
    flipDescriptionHolder  =  layoutInflater.inflate(R.layout.flip_view_profile_description, null);

    profileFlipper = (ViewFlipper) findViewById(R.id.profile_flipper);

    profileFlipper.addView(flipViewMain);
    profileFlipper.addView(flipListHolder);
    profileFlipper.addView(flipDescriptionHolder);

    flipInNextAnimation = AnimationUtils.loadAnimation(this, R.anim.push_left_in);
    flipOutNextAnimation = AnimationUtils.loadAnimation(this, R.anim.push_left_out);
    flipInPreviousAnimation = AnimationUtils.loadAnimation(this, R.anim.push_right_in);
    flipOutPreviousAnimation = AnimationUtils.loadAnimation(this, R.anim.push_right_out);
 }

  private void handleFlip(int position){
    if(position<currentPosition){
        profileFlipper.setInAnimation(flipInPreviousAnimation);
        profileFlipper.setOutAnimation(flipOutPreviousAnimation);
    } else if(position>currentPosition){
        profileFlipper.setInAnimation(flipInNextAnimation);
        profileFlipper.setOutAnimation(flipOutNextAnimation);
    }
    currentPosition = position;

    profileFlipper.setDisplayedChild(position);
}

所有的动画都是这样的:

<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />

 </set>

我做错了什么?我怎样才能摆脱这种滞后?我想也许我会更好地使用 ViewPager 但它似乎在动画修改方面不是很灵活。谢谢。

最佳答案

显然问题不是由 ViewFlipper 引起的。只有在我的 Galaxy Nexus 设备上进行调试时,我才注意到动画滞后。我发现了 here那:

The Galaxy Nexus is 1280 x 720 for a total of 921K pixels on screen. So basically, the GPU on the Galaxy Nexus has to draw 2.4 times as many pixels per frame as the it does on the Infuse or S II. The potential frame rate can be expected to be roughly 2.4 times worse on the Galaxy Nexus as it can on the Infuse or Galaxy S II.

这就是我的动画问题的原因。通过启用硬件加速解决它:

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (android.os.Build.VERSION.SDK_INT >= 11) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
    }
    setContentView(R.layout.content);

    initUI();

}

关于Android viewflipper 动画滞后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14724270/

相关文章:

javascript - jQuery slider 导航问题

android - Android 8.1下nano pc t4板的屏幕方向纵向

java - 如何在Android中随机旋转图像?

javascript - 添加和删​​除类时应用过渡效果

html - 当用户滚动到页面的那一部分时激活 CSS 动画

android - 从网络加载图像时的占位符动画

javascript - 在 iOS 设备上停止 css 转换时元素会抖动

java - Android 开发套件 - 更改字符串的值

android - 错误: Error: String types not allowed (at 'layout_gravity' with value 'start' )

java - 使用 Linkify.addLinks 结合 Html.fromHtml