动画中的通知栏自定义视图 [英] Animation in Notification bar Custom View

查看:166
本文介绍了动画中的通知栏自定义视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我知道我们可以在Android中使用通知管理器+远程视图创建的通知。

As far as I know we can create notifications in Android using Notification Manager + remote Views.

我创建通知下载MP3文件。我想它旁边的一个动画。到目前为止,我已经从论坛,这是不可能的教训。

I am Creating a notification for downloading Mp3 files. And I want an animations beside It. So far I have learned from forums that it is not possible.

不过,我看到了一个Android应用程序会下载并显示动画的旁边,同时下载它的视频。 链接:<一href="http://www.youtube.com/watch?v=yNcs-sS2nFU&feature=related">http://www.youtube.com/watch?v=yNcs-sS2nFU&feature=related

However I saw A video for an android App which downloads and displays animation beside it while downloading it. Link: http://www.youtube.com/watch?v=yNcs-sS2nFU&feature=related

谁可以告诉我实现这一目标的最佳途径。

Can someone tell me the best way to achieve it.

推荐答案

我已发现,以显示一个自定义动画中的通知的最佳方法是使用一个AnimationDrawable作为与ID的资源。他们只需指定绘制资源ID,当您发表您的通知。没有进一步的code是需要更新动画的每一帧。动画绘制处理你们。

The best way I have found to show a custom animation in a notification is to use an AnimationDrawable as a resource with an ID. Them simply specify the drawable resource ID when you post your notification. No further code is needed to update each frame of the animation. The animation drawable handles that for you.

下面是一个链接到文件:<一href="http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html">http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

Here is a link to documentation: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

因此​​,例如,你将需要:

So for example you would need to:

  1. 添加一个XML文件(如wheelAnim.xml)添加到您的 RES /绘制/ 的文件夹中有如下内容:

  1. Add an xml file (such as "wheelAnim.xml") to your res/drawable/ folder with the following contents:

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

  • 添加在您刚才的的动画列表中创建的XML文件中的每个绘制参考的(无论是PNG或其他图像格式)的 RES /绘制/ 文件夹中。

  • Add each drawable reference in the xml file you just created for the animation-list (be it PNG or other image format) in the res/drawable/ folder as well.

    使用动画列表(其在本例中为R.drawable.wheelAnim)在code的资源ID。例如:

    Use the resource ID of the animation-list (which in this example is "R.drawable.wheelAnim") in your code. For example:

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

  • 这篇关于动画中的通知栏自定义视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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