I have some basic animations that work like a charm when they are used for transitions between the activities.
The problem is that when I use them on my viewflipper I see a very noticeable lag.
Here is a code snippet from my activity:
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);
}
All animation are like this one:
<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="300"/>
<alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="300" />
</set>
What am I doing wrong? How can I get rid of this lag? I thought that maybe I would better use a ViewPager but it seems like it is not very flexible in terms of animation modifications. Thanks.
Apparently the problem was not caused by the ViewFlipper. I noticed the animation lag only when debugging on my Galaxy Nexus device. I found out here that:
That’s the reason for my animation problem. Solved it by enabling hardware acceleration: