当使用overridePendingTransition,修改UI的意见,在所谓的活动是很慢 [英] When using overridePendingTransition, modifying UI views in the called activity is very slow
问题描述
几天前,我曾与基于的结果更新一个操作栏
菜单图标问题的AsyncTask
:<一href="http://stackoverflow.com/questions/29239804/updating-action-bar-menu-item-due-to-asynctask-result-without-delay">Updating操作栏菜单项,由于AsyncTask的结果毫不拖延
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
现在我意识到,这个问题是不是在所有涉及到的的AsyncTask
或操作栏
。出现该问题,以及如果我想换一个的TextView
或任何其它查看
。
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
.
在摸索一段时间后,我意识到,这个问题是由overridePendingTransition我在活动使用
它调用第二个活动
(在这里我想更改图标):
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):
首先活动
(在onItemClick法):
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>
这是第二个活动的AsyncTask的(onPostExecute)怎么是这样的:
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);
}
}
正如所解释的,而不是两个菜单图标之间切换,则也可以使用一个TextView的以及基于结果中的文本 - 的问题仍然存在。
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
?
推荐答案
检查 integer.xml 文件 使价值 config_shortAnimTime 根据您的需求较小。 它以毫秒为单位。 preFER使得1000(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).
这篇关于当使用overridePendingTransition,修改UI的意见,在所谓的活动是很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!