Android 主屏幕小部件动画 [英] Android homescreen widget animations

查看:68
本文介绍了Android 主屏幕小部件动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究创建一个支持动画的小部件,最好是通过 android.view.animation 框架,否则通过在后台服务触发的代码中设置远程视图的属性.

I'm looking into creating a widget that supports animation, ideally via the android.view.animation framework, otherwise by setting properties on the remote views in code triggered from a background service.

有没有人对这两种方法有任何经验,我正在尝试可行的方法,还是我正走向死胡同?

Does anyone have any experience with either of these approaches, and is what I'm trying doable, or am I heading up a blind alley?

推荐答案

实际上可以为 RemoteView 小部件设置动画.问题是它的设计限制非常严格,因为在系统进程中运行自定义代码会带来安全隐患.

It's actually possible to animate RemoteView widgets. The problem is it is super restrictive which is by design because of the security implications of running custom code in a system process.

我的意思是,Android 只能处理通过 xml 绑定到布局的 res/anim xml 文件中表达的动画.一些 RemoteView 小部件支持这个

What I mean by this is that Android will only work with animations that are expressed in res/anim xml files that are tied to layouts via xml. Some RemoteView widgets support this

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

An example of this is the News and Weather app widget that comes on a stock android system. What it is doing is using a ViewFlipper to cycle through each news story every 10 seconds or so.

    <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>

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

In this example you can tie pending intents to each TextView. So when a user clicks on any one a different action can occur.

最后,Android 一直在缓慢地在每个版本中添加对动画视图的支持.例如 TransitionDrawables(交叉淡入淡出选择器可绘制)直到 Android 3.0 才交叉淡化.

Lastly, Android has been slowly adding support for animated views in each version. For example TransitionDrawables (cross fading selector drawable) don't cross-fade until Android 3.0.

这篇关于Android 主屏幕小部件动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆