Android主屏幕小部件动画

Adr*_*ian 32 animation android android-widget

我正在寻找创建一个支持动画的小部件,理想情况下通过android.view.animation框架,否则通过在后台服务触发的代码中设置远程视图的属性.

有没有人对这些方法中的任何一种都有任何经验,而且我正在尝试做什么,或者我是否正在走向死胡同?

Jer*_*rds 14

实际上可以为RemoteView小部件设置动画.问题是由于在系统进程中运行自定义代码的安全隐患,它是超级限制的.

我的意思是Android只能使用res/anim xml文件中表示的动画,这些动画通过xml与布局相关联.一些RemoteView小部件支持这一点

这方面的一个例子是股票Android系统上的新闻和天气应用程序小部件.它正在做的是使用ViewFlipper每10秒左右循环一次每个新闻报道.

    <ViewFlipper android:layout_width="match_parent" android:layout_height="wrap_content" android:measureAllChildren="true" android:flipInterval="10000" android:autoStart="true"
android:inAnimation="@android:anim/fade_in" android:outAnimation="@android:anim/fade_out" android:animateFirstView="true">
      <TextView android:id="@+id/Description1TextView" style="@style/AWCText.Centered" android:layout_width="match_parent" android:layout_height="wrap_content"/>
      <TextView android:id="@+id/Description2TextView" style="@style/AWCText.Centered" android:layout_width="match_parent" android:layout_height="wrap_content"/>
      <TextView android:id="@+id/Description3TextView" style="@style/AWCText.Centered" android:layout_width="match_parent" android:layout_height="wrap_content"/>
      <TextView android:id="@+id/Description4TextView" style="@style/AWCText.Centered" android:layout_width="match_parent" android:layout_height="wrap_content"/>
    </ViewFlipper>
Run Code Online (Sandbox Code Playgroud)

在此示例中,您可以将挂起的意图绑定到每个TextView.因此,当用户点击任何一个时,可能会发生不同的操作.

最后,Android在每个版本中都慢慢添加了对动画视图的支持.例如,TransitionDrawables(交叉淡入淡出选择器drawable)在Android 3.0之前不会交叉淡入淡出.