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

来源:互联网 发布:相片时间修改软件 编辑:程序博客网 时间:2024/05/16 06:48
private static Animation createAnimationFromXml(Context c, XmlPullParser parser,            AnimationSet parent, AttributeSet attrs) throws XmlPullParserException, IOException {                Animation anim = null;         // Make sure we are on a start tag.        int type;        int depth = parser.getDepth();        while (((type=parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth)               && type != XmlPullParser.END_DOCUMENT) {            if (type != XmlPullParser.START_TAG) {                continue;            }            String  name = parser.getName();                if (name.equals("set")) {                anim = new AnimationSet(c, attrs);                createAnimationFromXml(c, parser, (AnimationSet)anim, attrs);            } else if (name.equals("alpha")) {                anim = new AlphaAnimation(c, attrs);            } else if (name.equals("scale")) {                anim = new ScaleAnimation(c, attrs);            }  else if (name.equals("rotate")) {                anim = new RotateAnimation(c, attrs);            }  else if (name.equals("translate")) {                anim = new TranslateAnimation(c, attrs);            } else {                throw new RuntimeException("Unknown animation name: " + parser.getName());            }            if (parent != null) {                parent.addAnimation(anim);            }        }            return anim;    }

原创粉丝点击