How To Do Interactive Animation (translation) With Android
I have some png sequences in Android, that I need to animation their x and y postion translation from the top to the bottom of the screen. While the animation is occurring, I need
Solution 1:
You're right, the issue is that pre-Honeycomb, only the visual aspect of your animating view is occurring.
This means that in addition to doing the "visual" animation, you also have to set/animate the frame/LayoutParams of the animated view.
For pre-Honeycomb devices, I find http://nineoldandroids.com/ very useful for listening to an animation which you can use for setting the LayoutParams of the view appropriately, but there are other examples as well, such as this one on SO: https://stackoverflow.com/a/3952933/429047
Solution 2:
This is what I ended up doing, which works pretty well.
MyTranslateAnimationanimation=newMyTranslateAnimation(ticket, 10, 100, -500, ticketHolder.getHeight());
And here is my class:
publicclassMyTranslateAnimationextendsAnimation {
privatefloat fromXDelta;
privatefloat fromYDelta;
privatefloat toXDelta;
privatefloat toYDelta;
private View view;
publicMyTranslateAnimation(View view, float fromXDelta,
float toXDelta, float fromYDelta, float toYDelta) {
this.view = view;
this.fromXDelta = fromXDelta;
this.toXDelta = toXDelta;
this.fromYDelta = fromYDelta;
this.toYDelta = toYDelta;
}
@OverrideprotectedvoidapplyTransformation(float interpolatedTime,
Transformation t) {
Log.d("united", "time " + interpolatedTime);
floatnewX= (toXDelta - fromXDelta) * interpolatedTime;
floatnewY= (toYDelta - fromYDelta) * interpolatedTime;
LayoutParamsp= (LayoutParams) view.getLayoutParams();
p.leftMargin = (int) newX;
p.topMargin = (int) newY;
if (interpolatedTime > 0.0 && view.getVisibility() == View.GONE) {
view.setVisibility(View.VISIBLE);
}
view.requestLayout();
}
}
Post a Comment for "How To Do Interactive Animation (translation) With Android"