Animations的使用(二)

使用代码编写:好处:易调试bug, 坏处:可重用性差

使用xml编写: 好处:n个控件使用同一动画则只需一个xml文件


使用xml:

1,在res文件夹下面新建一个文件夹,名anim

2,新建xml文件,首先加入一个set标签,改标签

<set
xmlns:android="http://schemas.android.com/apk/res/android">
</set>

3,在该标签中加入子标签,alpha等。

4,在代码中使用AnimationUtils加载xml文件,并生成Animation对象。


代码:

xml文件:

<set
xmlns:android="http://schemas.android.com/apk/res/android">
<alpha 
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:startOffset="500"
android:duration="500"/>
</set>

主程序:

Animation animation=AnimationUtils.loadAnimation(TestActivity.this, R.anim.anim);
iv_icon.setAnimation(animation);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章