Reputation: 17581
In my app I add a TextView programmatically and after I do an animation (traslate+alpha) in this way
TextView point = new TextView(getApplicationContext());
//... all option for the TextView
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move_result_point);
anim.setAnimationListener(this);
point.startAnimation(anim);
my xml animation is
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromYDelta="0%p"
android:toYDelta="-50%p"
android:duration="700"
/>
<alpha
android:fromAlpha="1"
android:toAlpha="0"
android:duration="700"/>
</set>
The now I want to remove the TextView generated when the animation finish, I know that I can do it in
@Override
public void onAnimationEnd(Animation arg0) {
}
but how I can recognize the exact TextView that I generated in the other method? I can generated many TextView in my layout... can you help me?
thanks
Upvotes: 0
Views: 696
Reputation: 22064
How about this?
public class ViewAnimationListener implements AnimationListener {
View view;
public void setView(View view) {
this.view = view;
}
public void onAnimationEnd(Animation animation) {
// Do whatever you want with your view
}
public void onAnimationRepeat(Animation animation) {
}
public void onAnimationStart(Animation animation) {
}
}
So when you want to animate your TextView:
ViewAnimationListener listener = new ViewAnimationListener();
listener.setView(point);
Animation anim = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move_result_point);
anim.setAnimationListener(listener);
point.startAnimation(anim);
Upvotes: 2