问题
a few days ago, I had a problem with updating an Action Bar
menu icon based on the result of an AsyncTask
: Updating Action Bar Menu Item due to AsyncTask result without delay
Now I realized that this problem is not at all related to an AsyncTask
or an Action Bar
. The problem occurs as well if I want to change a TextView
or any other View
.
After some time of trial and error I realized that the problem is caused by overridePendingTransition which I use in the Activity
which calls the second Activity
(where I want to change the icon):
First Activity
(in an onItemClick method):
@Override
public void onItemClick(View view, int position) {
...
Intent intent = new Intent(getActivity(), SecondActivity.class);
...
startActivityForResult(intent, anyValue);
getActivity().overridePendingTransition(R.anim.slide_in_right, R.anim.no_animation);
}
The animation looks like that:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="100%p" android:toXDelta="0"
android:duration="@android:integer/config_shortAnimTime"/>
</set>
And this is how the AsyncTask (onPostExecute) of the second Activity looks like:
@Override
public void onPostExecute(String result) {
super.onPostExecute(result);
if (mMenu != null) {
if (result.equals("no favorite")) {
...
mMenu.findItem(R.id.action_favorite).setVisible(false);
mMenu.findItem(R.id.action_no_favorite).setVisible(true);
} else {
...
mMenu.findItem(R.id.action_favorite).setVisible(true);
mMenu.findItem(R.id.action_no_favorite).setVisible(false);
}
}
As explained, instead of switching between two menu icons, you could also use one TextView and setting the text based on the result - the problem remains.
Do you know how I can change the animation without having this weird delay in my second Activity
?
回答1:
Check your integer.xml file Make the value of config_shortAnimTime smaller according to your needs. Its in milliseconds. Prefer making it 1000 (1 sec).
来源:https://stackoverflow.com/questions/29318415/when-using-overridependingtransition-modifying-ui-views-in-the-called-activity