gpt4 book ai didi

Android viewflipper 动画滞后

转载 作者:行者123 更新时间:2023-11-30 03:47:34 32 4
gpt4 key购买 nike

我有一些基本的动画,当它们用于 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com