Android Animation Leaves Lines During Movement
Solution 1:
So I solved the problem but not in a way that I'm happy with.
First at a place in my code I wasn't showing I called:
cardButton.setBackgroundColor(Color.WHITE);
If I commented out this line the problem went away. This however produced CardButtons that looked like stock android buttons. This isn't how I wanted them to look, so I tried setting the white button "style" a number of other ways. All of which produced the bug.
In an attempt to better understand what was going on and to hunt down a possible bug in either Android or my code I created a test project that only included one activity with the 3x4 grid and nothing else. This test project contained a single activity and a single XML file. Starting with a basic grid I was un able to reproduce the bug, then I started adding more and more features to the test app and eventually had recreated the original activity but without the bug.
I thought maybe something about my new implementation was better than the original so I incorporated the new test activity into my original project. However, when I ran the test activity from original project the bug showed up again.
I now have two activities that use identical code in different Android Projects. One is the only activity in the project while the other is part of a larger project with many activities. The version in the larger project exhibits the bug while the version in the stand alone project does not. I'm not sure how to interpret this and I'd greatly appreciate any feedback/comments on this.
So until I can figure out why I get the drawing error in the context of my bigger application I'm going to use the stock android button background.
Update: On a whim I made a 9Patch background that was white. This fixed the problem.
Solution 2:
This might be causing the issue. Sometime the animations onAnimationEnd fires a bit before the actual animation is done.
You can create a custom view or layout and overide its 'animationEnd' method and add a interface so you can set up a listener.
Here's an example
CustomLayout class
public class CustomLayout extends LinearLayout {
private LayoutAnimationListener mListner;
public CustomLayout(Context context) {
super(context);
}
public CustomLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onAnimationEnd() {
super.onAnimationEnd();
if(mListner != null){
mListner.onAnimationEnd(CustomLayout.this);
}
}
@Override
protected void onAnimationStart() {
super.onAnimationStart();
if(mListner != null){
mListner.onAnimationStart(CustomLayout.this);
}
}
public static interface LayoutAnimationListener {
//Notifies the start of the animation.
void onAnimationStart(CustomLayout cLayout);
//Notifies the end of the animation.
void onAnimationEnd(CustomLayout cLayout);
}
public void setLayoutAnimationListener(LayoutAnimationListener listener){
mListner = listener;
}
}
So in your activity you can use it as a normal linearlayout and instead of adding a animation listener to the animation, you can add it to the layout like
com.blessan.CustomLayout layout =
(com.blessan.CustomLayout)findViewById(R.id.counts_layout);
LayoutAnimationListener layoutAnimListener = new LayoutAnimationListener() {
@Override
public void onAnimationStart(CustomLayout cLayout) {
}
@Override
public void onAnimationEnd(CustomLayout cLayout) {
}
};
layout.setLayoutAnimationListener(layoutAnimListener);
This might work for you. Give it a try.
Solution 3:
Improvement/could-be Answer :
I have a improvement on your code, hope it fixes your refresh problem too. Also feel this is the right way to do what you are trying.
growShrink.addAnimation(ta);
growShrink.addAnimation(sa);
holdAnim.setStartOffset(growDuration); // hold will start when grow stops.
growShrink.addAnimation(holdAnim);
growShrink.setRepeatCount(1);
growShrink.setRepeatMode(Animation.REVERSE);
growShrink.setInterpolator(new LinearInterpolator());
This will play the growing animation in reverse. No need of animation end listener to start the hold and shrink animations.
Alternate solution:
Add all your growing, holding and shrinking animations to one AnimtaionSet. Set the start offsets of hold and shrink animations appropriately.
// growAnim will start at 0.
holdAnim.setStartOffset(growDuration);
shrinkAnim.setStartOffset(growDuration+holdDuration);
Post a Comment for "Android Animation Leaves Lines During Movement"