MainActivity
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } public void openActivity(View v) { Intent intent = new Intent(this, OtherActivity.class); startActivity(intent); //屏幕动画弹入效果切换,调用anim文件夹中创建的enteralpha(进入动画)和exitalpha(淡出动画)两个动画(注意:两个xml文件命名不能有大写字母) //如果想定义其他动画效果,只需要改变enteralpha和exitalpha两个文件 this.overridePendingTransition(R.anim.enteralpha, R.anim.exitalpha); } }
OtherActivity
import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; public class OtherActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_other); } public void openActivitya(View v) { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); //屏幕动画弹入效果切换,调用anim文件夹中创建的enteralpha(进入动画)和exitalpha(淡出动画)两个动画(注意:两个xml文件命名不能有大写字母) //如果想定义其他动画效果,只需要改变enteralpha和exitalpha两个文件 this.overridePendingTransition(R.anim.enteralpha, R.anim.exitalpha); } }
anim
调用anim文件夹中创建的enteralpha(进入动画)和exitalpha(淡出动画)两个动画(注意:两个xml文件命名不能有大写字母)
enteralpha.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false" > <!-- 动画效果 从看不见到可以看见,也就是0到1,变幻时间为5000毫秒--> <!-- <alpha android:fromAlpha="0" android:toAlpha="1" android:duration="20000" />--> <!--下面这个是实现android activity 从下往上弹出的动画--> <translate android:duration="300" android:fromYDelta="100.0%" android:toYDelta="10.000002%" /> <alpha android:duration="50" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set>
exitalpha.xml
<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <!-- 退出动画效果 从可以看见到不可以看见,也就是1.0到0,变幻时间为5000毫秒--> <!-- <alpha android:fromAlpha="1.0" android:toAlpha="0" android:duration="2000" />--> <!--下面这个是实现android activity 从下往上弹出的动画--> <translate android:duration="300" android:fromYDelta="100.0%" android:toYDelta="10.000002%" /> <alpha android:duration="50" android:fromAlpha="0.0" android:toAlpha="1.0" /> </set>
布局
activity_main
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.dell.glide_activity.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello" android:onClick="openActivity"/> </LinearLayout>
activity_other
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.dell.glide_activity.OtherActivity"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/new_activity" android:onClick="openActivitya" /> </LinearLayout>
values
strings
<resources>
//这个是你的项目名 <string name="app_name">Glide_Activity</string> <string name="hello">打开新Activity</string> <string name="new_window">新窗口</string> <string name="new_activity">这是新Activity</string> </resources>