Skip to content Skip to sidebar Skip to footer

Android - Remove View When Its Animation Finished

Hey I have a method which adds a TextView to my FrameLayout and starts the Animation. The method should be able to be called more often (for multiple Animations). That is working

Solution 1:

It's likely that you will have issues removing the view in this way since you should only be attempting to touch any of your views from the UI thread (to avoid other threads trying to change your UI elements at the same time which will just cause problems). For this reason Android provides a method called runOnUiThread() that will instruct your code to perform an action in the correct thread.

Something like this should get you pointed in the right direction. Place this in your onAnimationEnd method.

//get the parentView...
parentView.post(new Runnable() {
    publicvoidrun () {
        // it works without the runOnUiThread, but all UI updates must // be done on the UI thread
        activity.runOnUiThread(new Runnable() {
            publicvoidrun() {
                parentView.removeView(view);
            }
        });
    }
}

Solution 2:

Try this:

  1. Make sure bgFl is not null
  2. You can try: temp.setVisibility(View.GONE) instead of remove

Or

  1. Use handler to remove view safely in UI thread.

Post a Comment for "Android - Remove View When Its Animation Finished"