【问题标题】:Displaying activity with custom animation使用自定义动画显示活动
【发布时间】:2011-03-06 11:12:54
【问题描述】:

我有一个小部件,当它被点击时它会启动一个活动。我想要一些花哨的动画来显示这个活动,而不是 Android 的标准从右滚动。不过,我在设置它时遇到了问题。这就是我所拥有的:

slide_top_to_bottom.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate android:fromYDelta="-100%" android:toXDelta="0" android:duration="100" />
    <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="50" />
</set>

...在 anim.xml

中引用
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
        android:delay="50%"
        android:animation="@anim/slide_top_to_bottom" />

但是我从哪里引用它呢?我已经尝试了我想要滑入的活动的基本元素,以及清单中的活动条目,两次都使用

android:layoutAnimation="@+anim/anim"

我可能做错了。非常感谢任何帮助!

【问题讨论】:

    标签: android animation android-widget


    【解决方案1】:

    您可以创建一个引用您自己的动画的自定义主题,并将其应用到清单文件中的 Activity。 我成功地使用以下样式定义为浮动窗口应用了自定义动画。如果您将样式的父级设置为“@android:style/Animation.Activity”,您也许可以做类似的事情

    查看以下文件以了解有关您可以覆盖的内容的更多详细信息。

    https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/styles.xml https://github.com/android/platform_frameworks_base/blob/master/core/res/res/values/themes.xml

    这是我的 style.xml 和 manifest.xml 的一部分

    styles.xml

    <style name="MyTheme" parent="@android:style/Theme.Panel">
        <item name="android:windowNoTitle">true</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:windowAnimationStyle">@style/MyAnimation.Window</item>
    </style>
    
    <!-- Animations --> 
    <style name="MyAnimation" /> 
    
    <!-- Animations for a non-full-screen window or activity. --> 
    <style name="MyAnimation.Window" parent="@android:style/Animation.Dialog"> 
        <item name="android:windowEnterAnimation">@anim/grow_from_middle</item>
        <item name="android:windowExitAnimation">@anim/shrink_to_middle</item>
    </style> 
    

    清单.xml

        <activity
            android:name="com.me.activity.MyActivity"
            android:label="@string/display_name"
            android:theme="@style/MyTheme">
        </activity>
    

    【讨论】:

      【解决方案2】:
      startActivity(intent);
      overridePendingTransition(R.anim.slide_top_to_bottom, R.anim.hold);
      

      查看此链接:overridePendingTransition method

      编辑:

      实现视图的动画。你已经使用了下面的 startAnimation 方法

      view.startAnimation(AnimationUtils.loadAnimation(
                       WidgetActivity.this,R.anim.slide_top_to_bottom));
      

      查看link

      【讨论】:

        【解决方案3】:

        从一个小部件开始,写一个教程,这样你就可以动画你的活动的进出,这并不重要。此动画设置在您关注的活动中,因此您也可以使用 pendingIntent 来实现。

        享受:

        http://blog.blundellapps.co.uk/animate-an-activity/

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-05-14
          • 1970-01-01
          • 2013-04-21
          • 1970-01-01
          • 2017-05-13
          • 1970-01-01
          • 2017-03-04
          相关资源
          最近更新 更多