通过设置theme方式实现切换activity动画效果
转载自:
http://blog.csdn.net/lnb333666/article/details/8962715
如题:反编译的了微信的包才知道这做饭,惭愧惭愧...
AndroidManifest.xml 注意application节点 的android:theme属性,这个属性是影响全局的,只要其它activity没有单独设置过theme就使用该theme:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.activityanimationdemo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".OneActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".TwoActivity" > </activity> <activity android:name=".ThreeActivity" > </activity> </application> </manifest>
看这里,主要的部分:styles.xml ,styples改要是用来改写系统提供的样式的东西,一般都是在item里面写着android:的样式,只是替换了系统提供的样式的东西:
<resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="AppTheme" parent="@android:style/Theme"> <!-- 设置没有标题 --> <item name="android:windowNoTitle">true</item> <!-- 设置activity切换动画 --> <item name="android:windowAnimationStyle">@style/activityAnimation</item> </style> <!-- animation 样式 --> <style name="activityAnimation" parent="@android:style/Animation"> <item name="android:activityOpenEnterAnimation">@anim/slide_right_in</item> <item name="android:activityOpenExitAnimation">@anim/slide_left_out</item> <item name="android:activityCloseEnterAnimation">@anim/slide_left_in</item> <item name="android:activityCloseExitAnimation">@anim/slide_right_out</item> </style> </resources>
slide_left_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="200" android:fromXDelta="-100.0%p" android:toXDelta="0.0" /> </set>
slide_left_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="200" android:fromXDelta="0.0" android:toXDelta="-100.0%p" /> </set>
slide_right_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="200" android:fromXDelta="100.0%p" android:toXDelta="0.0" /> </set>
slide_right_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <translate android:duration="200" android:fromXDelta="0.0" android:toXDelta="100.0%p" /> </set>
Activity 代码,很简单,就是startactivity而已不需要什么特别的
package com.example.activityanimationdemo; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; /** * * @fileName OneActivity.java * @author naibo-liao * @CreateTime 2013-5-20 上午11:55:04 */ public class OneActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.layout_one); findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(OneActivity.this, TwoActivity.class)); } }); // 返回事件 findViewById(R.id.btn_exit).setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } }
上一张工程图
就这些
相关推荐
xjp 2020-05-28
fengyeezju 2020-01-11
xilove0 2020-01-10
ALiDan 2019-12-16
JunkChen 2011-09-15
dingguagua 2013-07-23
缘来如此 2013-08-30
lihaoxiang 2019-11-14
Andrew的杂记 2010-10-07
luoj 2011-01-28
满城风絮 2011-09-09
doyouhaveIET 2011-08-31
Mexican 2011-08-31
Rgenxiao 2011-08-29
kangtingting0 2011-08-29
luoj 2011-08-23
西木 2011-08-17