2013-12-16 51 views
0

我在ListView中的行的佈局中有一個framelayout。當一個項目出現在列表視圖中時,AnimationDrawable被觸發。AnimationDrawable不顯示在4.03設備上

這適用於Nexus 4和Nexus 5.我不得不從view.setBackground更改爲view.setBackgroundDrawable以支持稍舊的設備。進行此更改並未在任何Nexus設備上打破。它也用於一箇舊的薑餅裝置。

在HTC One V上運行4.03。 AnimationDrawable從不出現。但是,如果我對行xml文件進行硬編碼以顯示標準drawable而不是animationdrawable,則看起來很好。

下面是XML文件中的animationdrawable

<item 
    android:drawable="@drawable/alert_red" 
    android:duration="700"/> 
<item 
    android:drawable="@drawable/alert_red_glow" 
    android:duration="700"/> 

</animation-list> 

這裏是一個啓動動畫

@SuppressWarnings("deprecation") 
     public void startGlowingRow() { 
      notificationStatus 
        .setBackgroundDrawable(getResources().getDrawable(
           R.drawable.glowing_emergency_notification)); 
      glowRequest = new GlowRequest(); 
      notificationStatus.post(glowRequest); 

     } 

     public void stopGlowingRow() { 
      try { 
       // Remove any callbacks to make background glowing 
       if (glowRequest != null) 
        notificationStatus.removeCallbacks(glowRequest); 

       glowDrawable = (AnimationDrawable) notificationStatus 
         .getBackground(); 
       glowDrawable.stop(); 
      } catch (ClassCastException cce) { 
       // Not the correct background in view so don't try to stop 
      } 
     } 

     // Runnable which sets glowing effect after view has loaded 
     private class GlowRequest implements Runnable { 

      public void run() { 

       glowDrawable = (AnimationDrawable) notificationStatus 
         .getBackground(); 
       glowDrawable.start(); 
      } 

     } 

回答

0

我終於想通了這一點的代碼。這是因爲包含動畫的視圖使用填充來顯示它的背景。當我改變這個,這是它的第一個孩子使用了保證金,而不是它工作得很好