标签:
只有不断找寻机会的人才会及时把握机会。
本讲内容:利用Theme自定义Activity间的切换动画
大多Android系统默认Activity间的动画切换效果为,右边滑入,左边滑出;有时候我们的需求可能是要求所有Activity的切换为淡入淡出的效果,这时候就可能需要改变一下默认的切换风格。
示例效果图:
下面是res/layout/activity_main.xml 布局文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/c1" > </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/c2" android:orientation="vertical" > </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:duration="3000" android:fromAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="1.0" /> </set>
下面是新建res/anim/fade_out.xml文件:
<?xml version="1.0" encoding="utf-8"?> <alpha xmlns:android="http://schemas.android.com/apk/res/android" android:duration="3000" android:fromAlpha="1.0" android:interpolator="@android:anim/accelerate_interpolator" android:toAlpha="0.0" />
<style name="Anim_fade" parent="android:Theme.NoTitleBar"> <item name="android:windowAnimationStyle">@style/fade</item> </style> <style name="fade" parent="@android:style/Animation.Activity"> <item name="android:activityOpenEnterAnimation">@anim/fade_in</item> <item name="android:activityOpenExitAnimation">@anim/fade_out</item> <item name="android:activityCloseEnterAnimation">@anim/fade_in</item> <item name="android:activityCloseExitAnimation">@anim/fade_out</item> </style>
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.custom" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" > <activity android:name="com.example.custom.MainActivity" android:label="@string/app_name" android:theme="@style/Anim_fade" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".AppActivity" android:theme="@style/Anim_fade"></activity> </application> </manifest>
public class MainActivity extends Activity { private Handler handler=new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); handler.postDelayed(new Runnable() { @Override public void run() { Intent intent=new Intent(MainActivity.this,AppActivity.class); startActivity(intent); finish(); } }, 1000); } }
public class AppActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.first); } }
标签:
原文地址:http://blog.csdn.net/liguojin1230/article/details/44339571