Android - 如何使用缩放和淡入淡出效果打开一个活动

时间:2016-05-03 12:08:28

标签: android android-animation

我有一个应用,我想使用this transition打开activity (如果您打开设置,Google地图也会这样做。)

我怎样才能做到这一点?

3 个答案:

答案 0 :(得分:1)

在下一个活动的oncreate方法中编写代码

答案 1 :(得分:1)

为淡入动画创建XML文件/res/anim/fadein.xml。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
  android:fromAlpha="0.1"
  android:toAlpha="1.0"
  android:duration="2000"
  />
</set>

为淡出动画创建XML文件/res/anim/fadeout.xml。

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator">
<alpha
  android:fromAlpha="1.0"
  android:toAlpha="0.1"
  android:duration="2000"
  />
</set>

Activity

final Animation animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein);
buttonToNextActivity.setOnClickListener(new Button.OnClickListener(){

  @Override
 public void onClick(View arg0) {
   // TODO Auto-generated method stub
  image.startAnimation(animationFadeIn);
  }});

SecondActivity中的写入相同并调用动画onBackPressed(){...}

答案 2 :(得分:0)

尝试在开始活动后添加以下行:

overridePendingTransition(R.anim.youranimation, R.anim.default_anim);

例如:

Intent intent = new Intent (context, YourActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.youranimation, R.anim.default_anim);

default_anim.xml:

<?xml version="1.0" encoding="utf-8"?>

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="@android:integer/config_shortAnimTime"
    android:fromYDelta="0%p"
    android:toYDelta="0%p" />

更改值。

相关问题