I´m working with "android.support.v4.Fragment"´s, and the animation I´m doing this way...
FragmentManager fm = getSupportFragmentManager();
fm.popBackStack();
FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right, R.anim.slide_in_left, R.anim.slide_out_right);
ImageView ivStart = (ImageView) findViewById(R.id.ivStart);
ivStart.setColorFilter(Color.rgb(80, 80, 80), android.graphics.PorterDuff.Mode.MULTIPLY);
ll_content_frame.setVisibility(View.INVISIBLE);
String itemName = "";
if (position <= (dataList.size() - 1))
itemName = (dataList.get(position)).getItemName();
if (itemName.equalsIgnoreCase(PResText.getString("Inputs_Outputs"))) {
DigIO digIO = new DigIO();
ft.replace(R.id.content_frame, digIO, DigIO.TAG);
ft.addToBackStack(DigIO.TAG);
ft.commit();
fm.executePendingTransactions();
}
.
.
XML like this...
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromXDelta="-100%"
android:toXDelta="0%"
>
</translate>
Now I´m trying to notice with a listener or something else, when fade_out animation, started within onBackPressed() by popBackStack(), is being done.
I´ve tried this code... by extending my fragments from these class.
public class MyFragment extends android.support.v4.app.Fragment {
private static final String TAG = "MyFragment";
@Override
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
Animation anim = AnimationUtils.loadAnimation(getActivity(), nextAnim);
anim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
Log.d(TAG, "Animation started.");
// additional functionality
}
@Override
public void onAnimationRepeat(Animation animation) {
Log.d(TAG, "Animation repeating.");
// additional functionality
}
@Override
public void onAnimationEnd(Animation animation) {
Log.d(TAG, "Animation ended.");
// additional functionality
}
});
return anim;
}
}
but this listener only responds at fade_in animation.
Kind regards proto
I have thought about this matter a while back. If I understand right, you want to know when the Fragment is finished. From FragmentManager, you can get the Fragment. Certainly you know which Fragment you're interested.
My suggestion is to override Fragment methods, either
onDetach
() oronDestroy
(), occurs before onDetach.