我怎样才能打开动画编程? [英] How can I turn on animation programatically?
问题描述
我怎样才能打开动画编程?我使用 overridePendingTransition();
。它不工作,除非我自己打开的动画。谁能告诉我怎么打开动画编程这是内部的显示/动画设置?我使用overridePendingTransition();打开新的活动。
下面是我的XML
grow_fadein_center
<?XML版本=1.0编码=UTF-8&GT?;<设置的xmlns:机器人=http://schemas.android.com/apk/res/android>
<规模以上的android:fromXScale =0.6机器人:toXScale =1.0
机器人:fromYScale =0.6机器人:toYScale =1.0
机器人:pivotX =50%的android:pivotY =50%
机器人:时间=@安卓整数/ config_longAnimTime/>
<阿尔法机器人:插值=@动画/ decelerate_interpolator
机器人:fromAlpha =0.0机器人:toAlpha =1.0
机器人:时间=@安卓整数/ config_longAnimTime/>
< /集>
shrink_fadeout_center:
<?XML版本=1.0编码=UTF-8&GT?;
<设置的xmlns:机器人=http://schemas.android.com/apk/res/android>
<规模以上的android:fromXScale =1.0机器人:toXScale =0.5
机器人:fromYScale =1.0机器人:toYScale =0.5
机器人:pivotX =50%的android:pivotY =50%
机器人:时间=@安卓整数/ config_longAnimTime/>
<阿尔法机器人:插值=@动画/ accelerate_interpolator
机器人:fromAlpha =1.0机器人:toAlpha =0.0
机器人:时间=@安卓整数/ config_longAnimTime/>
< /集>
和这里是code我使用打开的意图
btn.setOnClickListener(新OnClickListener(){ @覆盖
公共无效的onClick(视图v){
// TODO自动生成方法存根 ContentResolver的CR = getContentResolver();
Settings.System.putInt(CR,Settings.System.WINDOW_ANIMATION_SCALE,0); 意向意图=新意图(背景下,Second.class);
startActivity(意向);
overridePendingTransition(R.anim.grow_fade_in_center,R.anim.shrink_fade_out_center);
完();//在TextView的测试工作没有开启系统的动画。
动画动画= AnimationUtils.loadAnimation(背景下,R.anim.grow_fade_in_center);
txt.startAnimation(动画);
}
});
这只有在动画开启工作。而我通过设置 - >显示 - >动画
我发现
ContentResolver的CR = getContentResolver();
Settings.System.putInt(CR,Settings.System.WINDOW_ANIMATION_SCALE,0);
要打开或关闭动画通过设置整数!但它并没有对我的工作!
我需要的是我怎么能打开/关闭动画编程这是在系统设置?
您不需要务实启动动画类的。
您只需要调用 overridePendingTransition(R.anim.grow_fade_in_center,R.anim.shrink_fade_out_center);
在正确的位置。
公共无效的onClick(视图v){
startActivity(HomeActivity.class);
overridePendingTransition(android.R.anim.fade_in,android.R.anim.fade_out);
完();
}
也做的:
Settings.System.putInt(CR,Settings.System.WINDOW_ANIMATION_SCALE,0);
请问禁用窗口动画!
How can I turn on animation programatically? I am using overridePendingTransition();
. It doesn't work unless I turn on animation myself. Can anybody tell me how to turn on animations programatically which are inside display/Animation setting? I am using overridePendingTransition(); to open new activity .
here are my xml
grow_fadein_center
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="0.6" android:toXScale="1.0"
android:fromYScale="0.6" android:toYScale="1.0"
android:pivotX="50%" android:pivotY="50%"
android:duration="@android:integer/config_longAnimTime" />
<alpha android:interpolator="@anim/decelerate_interpolator"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="@android:integer/config_longAnimTime" />
</set>
shrink_fadeout_center :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="1.0" android:toXScale="0.5"
android:fromYScale="1.0" android:toYScale="0.5"
android:pivotX="50%" android:pivotY="50%"
android:duration="@android:integer/config_longAnimTime" />
<alpha android:interpolator="@anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0"
android:duration="@android:integer/config_longAnimTime"/>
</set>
and here is the code i am using to open intent
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ContentResolver cr = getContentResolver();
Settings.System.putInt(cr, Settings.System.WINDOW_ANIMATION_SCALE, 0);
Intent intent=new Intent(context,Second.class);
startActivity(intent);
overridePendingTransition(R.anim.grow_fade_in_center, R.anim.shrink_fade_out_center);
finish();
//testing on textview worked without turning system animation on.
Animation animation=AnimationUtils.loadAnimation(context, R.anim.grow_fade_in_center);
txt.startAnimation(animation);
}
});
This works only when animations are turned on. and i am doing so by settings->display->animation
I found
ContentResolver cr = getContentResolver();
Settings.System.putInt(cr, Settings.System.WINDOW_ANIMATION_SCALE, 0);
to turn on or off animation by setting integer! but it didn't work for me! what i need is how can i turned on/off animation programatically which are in system setting?
You do not need to initiate the Animation pragmatically like that.
You just need to call overridePendingTransition(R.anim.grow_fade_in_center, R.anim.shrink_fade_out_center);
in the correct place.
public void onClick(View v) {
startActivity(HomeActivity.class);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
Also doing:
Settings.System.putInt(cr, Settings.System.WINDOW_ANIMATION_SCALE, 0);
Will disabled window animations!
这篇关于我怎样才能打开动画编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!