【问题标题】:Android viewflipper animation lagAndroid viewflipper 动画滞后
【发布时间】:2013-02-06 08:07:55
【问题描述】:

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

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

 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,但它在动画修改方面似乎不是很灵活。谢谢。

【问题讨论】:

    标签: android animation transition viewflipper lag


    【解决方案1】:

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

    Galaxy Nexus 的屏幕尺寸为 1280 x 720,屏幕总像素为 921K。 所以基本上,Galaxy Nexus 上的 GPU 必须绘制 2.4 倍 每帧有很多像素,就像在 Infuse 或 S II 上一样。 Galaxy Nexus 的潜在帧速率预计会比 Infuse 或 Galaxy S II 低 2.4 倍。

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

     @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();
    
    }
    

    【讨论】:

      猜你喜欢
      • 2015-04-13
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 1970-01-01
      • 2021-03-04
      • 1970-01-01
      • 1970-01-01
      • 2013-10-27
      相关资源
      最近更新 更多