自己为Activity做的启动、关闭动画。
在AndroidManifest.xml中
<activity android:name="com.test.PrizeActivity" android:theme="@style/activity_styleprize"/>
在res/values/styles.xml中设置activity_styleprize
<style name="activity_styleprize"> <item name="android:windowNoTitle">true</item> <item name="android:windowBackground">@android:color/transparent</item> <item name="android:colorBackgroundCacheHint">@null</item> <item name="android:windowIsTranslucent">true</item> <!-- Note that we use the base animation style here (that is no animations) because we really have no idea how this kind of activity will be used. --> <item name="android:windowAnimationStyle">@style/AnimationActivity</item> </style> <style name="AnimationActivity" parent="@android:style/Animation"> <item name="android:activityOpenEnterAnimation">@anim/activity_open</item> <item name="android:activityOpenExitAnimation">@anim/activity_close</item> <item name="android:activityCloseEnterAnimation">@anim/activity_open</item> <item name="android:activityCloseExitAnimation">@anim/activity_close</item> </style>
res/anim/文件中加入
activity_open.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1500" android:fromYDelta="100%p" android:toYDelta="0" /> </set>
activity_close.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="1500" android:fromYDelta="25" android:toYDelta="100%p" /> </set>
同样使用下面的代码也可以实现PrizeActivity的打开动画和YaoActivity的关闭动画
Intent intent = new Intent(); PrizeModel prizeModel=(PrizeModel) msg.obj; intent.setClass(YaoActivity.this,PrizeActivity.class); YaoActivity.this.startActivity(intent); YaoActivity.this.overridePendingTransition(R.anim.activity_open,R.anim.activity_close);
时间: 2024-11-10 04:44:09