问题
I have successfully changed the transitions between activities using overridePendingTransition()
.
Unfortunately when I am on a TabActivity
and use activities inside each tab. When one of those activities inside the content of the tab, starts another activity, the overridePendingTransition()
seems to not work.
I basically have a TabActivity
, inside it resides an activity with a ListView
. What I'm doing is when the item is clicked, I launch the item details' activity.
This new activity's transition animation is not being overridden with the overridePendingTransition()
I basically do this:
private Activity owner;
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent programActivity = new Intent().setClass(view.getContext(), ProgramActivity.class);
Program program = (Program) parent.getItemAtPosition(position);
programActivity.putExtra("programID", program.getId());
owner.startActivity(programActivity);
owner.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
So, I believe that the pending transition is overridden after I'm trying to override them.
Is there a different place I should do that? Am I doing some other stupid mistake?
Thanks !
回答1:
I had a similar problem with calling overridePendingTransition() from within a Fragment, because Fragments do not have overridePendingTransition() method defined.
I solved it using:
getActivity().overridePendingTransition(R.anim.enterAnim, R.anim.exitAnim);
Hope it helps. The Fragment was within a TabHost.
回答2:
I found out that the problem was because my view was a sub-activity inside a tab.
To correctly override the transitions I've overridden the onPause
method on the TabActivity
and it now works as expected.
Note: You still have to use the overridePendingTransition()
on the listener for your items if your activity is NOT within a tab.
来源:https://stackoverflow.com/questions/7759314/change-activity-transition-when-inside-a-tabhost