通知栏自定义视图中的动画

Jeh*_*adK 11 animation android widget push-notification android-layout

据我所知,我们可以使用Notification Manager +远程视图在Android中创建通知.

我正在创建下载Mp3文件的通知.而且我想要它旁边的动画.到目前为止,我从论坛中了解到这是不可能的.

但是我看到一个Android应用程序的视频,下载并在下载时显示旁边的动画.链接:http://www.youtube.com/watch?v = yNcs-sS2nFU&feature = related

有人能告诉我实现它的最佳方法.

Cap*_*ngo 26

我发现在通知中显示自定义动画的最佳方法是使用AnimationDrawable作为具有ID的资源.然后,只需在发布通知时指定可绘制资源ID.无需更多代码即可更新动画的每个帧.动画drawable为您处理.

以下是文档的链接: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>
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在您刚为该动画列表创建的xml文件中添加每个可绘制引用(也可以是PNG或其他图像格式)res/drawable/.

  3. 在代码中使用动画列表的资源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);
    
    Run Code Online (Sandbox Code Playgroud)

  • 我已经在较新的NotificationBuilder类中尝试了动画drawables作为小图标,它在状态栏中看起来很棒.但是,当您下拉通知抽屉时,图标不会动画.有没有人有这方面的经验,你有没有成功在下拉视图中制作动画图标? (2认同)