Is there a way to animate on a Home Widget?

前端 未结 5 1960
陌清茗
陌清茗 2020-12-01 09:51

I want to use an animation on a Home page Widget, i.e. an AppWidgetProvider. I was hoping to use the \"Frame Animation\" technique:

http://developer.android.com/gui

相关标签:
5条回答
  • 2020-12-01 10:18

    Do not animate app widgets, unless you write you own home screen app.

    You are correct that you have no way to manipulate an AnimationDrawable or an Animation to have them work with an app widget.

    You are also correct that "very fast onUpdate() calls on the widget...seems awfully expensive", because it is. Updates to app widgets involve inter-process communication, between your AppWidgetProvider and the process hosting the home screen. This system is designed for updates every 30 minutes or so, not 30 frames per second.

    0 讨论(0)
  • 2020-12-01 10:19

    Another option to animate a widget is the use of ViewFlipper, where one can use inAnimationand outAnimation:

        <ViewFlipper xmlns:android="http://schemas.android.com/apk/res/android"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
                 android:flipInterval="5000"
                 android:autoStart="true"
                 android:inAnimation="@android:anim/fade_in"
                 android:outAnimation="@android:anim/fade_out"
                 android:animateFirstView="true"/>
    
    0 讨论(0)
  • 2020-12-01 10:36

    One Widget that is available for use in a RemoteView is the ProgressBar. It will animate itself and will not chew up resources. An in-determinant ProgressBar which is a square will overlay quite well on a homescreen appwidget. See sample code from Android site

    0 讨论(0)
  • 2020-12-01 10:36

    Create custom animation. Create ProgressBar and set in android:indeterminateDrawable your animation. Add ProgressBar to your widget layout and make it visible(invisible)

    0 讨论(0)
  • 2020-12-01 10:39

    I am currently creating an widget that "need" sprite animation, and I have put a blog post on how to animate home widget. Yes, it is expensive to do, so I do it only when the widget is needed. BTW, original android animation is not supported in remote views.

    Edit:

    Demo Project is up.

    0 讨论(0)
提交回复
热议问题