【问题标题】:Replace android Launcher activity animations替换 android Launcher 活动动画
【发布时间】:2011-10-25 17:23:33
【问题描述】:

我正在创建自己的 Android 启动器。

问题是:

  • 当我启动一项活动时,它会向左滑动...
  • 当我关闭它时,它会向右滑动...
  • 这既烦人又丑陋!

我已经能够删除 launch 动画了:

Intent launch_intent = new Intent("android.intent.action.MAIN");
launch_intent.addCategory("android.intent.category.LAUNCHER");
launch_intent.setComponent(new ComponentName(packageName, name));
launch_intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);

activity.startActivity(launch_intent);

我的目标是:

  • 同时移除关闭应用程序动画。
  • 或更改启动/关闭默认动画。

提前致谢!

【问题讨论】:

  • 我的印象是这是由应用程序或操作系统本身控制的。我不知道如果不编写自己的 Android 发行版就可以做到这一点。
  • 也许this 可以帮忙?

标签: java android launcher


【解决方案1】:

我查看了 Android API 演示,建议您应该使用“overridePendingTransition()”方法,它设置传入活动的动画和传出活动的动画。
该方法应该在startActivity()之后或者finish()之后添加:

    Intent launch_intent = new Intent("android.intent.action.MAIN");
    launch_intent.addCategory("android.intent.category.LAUNCHER");
    launch_intent.setComponent(new ComponentName(packageName, name));  
    activity.startActivity(launch_intent);
    overridePendingTransition(R.anim.zoom_enter, R.anim.zoom_exit);

过渡是标准的 android 动画,例如 zoom_enter 将是这样的:

<set xmlns:android="http://schemas.android.com/apk/res/android"
        android:interpolator="@android:anim/decelerate_interpolator">
    <scale android:fromXScale="2.0" android:toXScale="1.0"
           android:fromYScale="2.0" android:toYScale="1.0"
           android:pivotX="50%p" android:pivotY="50%p"
           android:duration="@android:integer/config_mediumAnimTime" />
</set>

如果您还想在您的活动关闭时设置动画,例如当用户按下返回或主页按钮时,您应该将 overridePendingTransition() 添加到 onPause() 方法。
如果您想在其他应用程序启动 Activity 时设置动画,请在 super.onCreate() 之前添加 overridePendingTransition()。

【讨论】:

  • 我正在开发一个启动器,因此在许多启动的应用程序中,我无法更改它们的代码。我想禁用仅修改启动器的动画。
  • @inversus 在这种情况下,在 .startActivity() 之后添加 overridePendingTransition() 以便在从启动器打开应用程序时获得所需的转换,并在 super 之前添加 overridePendingTransition() .onCreate() 所以当启动器再次进入视野时,你也会得到你想要的过渡。
  • 我还需要将 overridePendingTransition() 添加到我的启动器活动的 onResume 中!启动器永远不会被销毁,因此它只会在启动时调用 onCreate。感谢您的帮助!
【解决方案2】:

要显示标准启动器动画,您必须为主要启动器活动应用特定主题。这个主题应该是(或应该继承自)android:Theme.Wallpaper。 android:theme="@android:style/Theme.Wallpaper"

对于此类主题,Android Framework 提供了您可能会在标准 Launcher 中看到的特定动画。

【讨论】:

    【解决方案3】:

    其实我也觉得这是一个刺激的动画,所以我也想改变它........我发现它 - 它是默认动画............检查这个链接........http://developer.android.com/reference/android/view/animation/GridLayoutAnimationController.html 所以我停止搜索这个问题....

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多