Android源码关于加载anim的xml文件的描述


Android源码关于加载anim的xml文件的描述

  1. private static Animation createAnimationFromXml(Context c, XmlPullParser parser,  
  2.             AnimationSet parent, AttributeSet attrs) throws XmlPullParserException, IOException {  
  3.           
  4.         Animation anim = null;  
  5.    
  6.         // Make sure we are on a start tag.   
  7.         int type;  
  8.         int depth = parser.getDepth();  
  9.   
  10.         while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)  
  11.                && type != XmlPullParser.END_DOCUMENT) {  
  12.   
  13.             if (type != XmlPullParser.START_TAG) {  
  14.                 continue;  
  15.             }  
  16.   
  17.             String  name = parser.getName();  
  18.       
  19.             if (name.equals("set")) {  
  20.                 anim = new AnimationSet(c, attrs);  
  21.                 createAnimationFromXml(c, parser, (AnimationSet)anim, attrs);  
  22.             } else if (name.equals("alpha")) {  
  23.                 anim = new AlphaAnimation(c, attrs);  
  24.             } else if (name.equals("scale")) {  
  25.                 anim = new ScaleAnimation(c, attrs);  
  26.             }  else if (name.equals("rotate")) {  
  27.                 anim = new RotateAnimation(c, attrs);  
  28.             }  else if (name.equals("translate")) {  
  29.                 anim = new TranslateAnimation(c, attrs);  
  30.             } else {  
  31.                 throw new RuntimeException("Unknown animation name: " + parser.getName());  
  32.             }  
  33.   
  34.             if (parent != null) {  
  35.                 parent.addAnimation(anim);  
  36.             }  
  37.         }  
  38.       
  39.         return anim;  
  40.   
  41.     }  

相关内容