通知栏自定义视图中的animation

据我所知,我们可以使用通知pipe理器+远程视图在Android中创build通知。

我正在创build一个下载MP3文件的通知。 我想在它旁边有一个animation。 到目前为止,我从论坛上了解到,这是不可能的。

然而,我看到一个android应用程序的video,下载并显示animation旁边下载它。 链接: http : //www.youtube.com/watch?v= yNcs-sS2nFU& feature=related

有人能告诉我实现它的最好方法吗?

我发现在通知中显示自定义animation的最佳方式是将AnimationDrawable用作具有ID的资源。 然后只需在发布通知时指定可绘制的资源ID。 不需要进一步的代码来更新animation的每个帧。 animationdrawable为您处理。

这是一个链接到文档: http : //developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

所以例如你需要:

  1. 添加一个xml文件(如“wheelAnim.xml”)到你的res / drawable /文件夹中,内容如下:

    <!-- Animation frames are wheel0.png -- wheel5.png files inside the res/drawable/ folder --> <animation-list android:id="selected" android:oneshot="false"> <item android:drawable="@drawable/wheel0" android:duration="50" /> <item android:drawable="@drawable/wheel1" android:duration="50" /> <item android:drawable="@drawable/wheel2" android:duration="50" /> <item android:drawable="@drawable/wheel3" android:duration="50" /> <item android:drawable="@drawable/wheel4" android:duration="50" /> <item android:drawable="@drawable/wheel5" android:duration="50" /> </animation-list> 
  2. res/drawable/文件夹中,为刚刚为animation列表 (也就是PNG或其他图像格式)创build的xml文件添加每个可绘制引用。

  3. 在代码中使用animation列表的资源ID(在本例中为“R.drawable.wheelAnim”)。 例如:

     Notification notification = new Notification(R.drawable.wheelAnim, null, System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(), 0); notification.flags |= Notification.FLAG_AUTO_CANCEL; notification.setLatestEventInfo(this, getText(R.string.someTitle), getText(R.string.someText), pendingIntent); ((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).notify( uid, notification); 

在用于创build状态栏通知的文档中 ,通过更改Notification类的iconLevel属性,您可以循环访问LevelListDrawable中定义的一LevelListDrawable图像:

iconLevel字段

此值指示用于通知图标的LevelListDrawable的当前级别。 您可以通过将该值更改为与LevelListDrawable中定义的drawable的关联来在状态栏中为图标添加animation。 有关更多信息,请参阅LevelListDrawable参考。