转自:http://www.open-open.com/lib/view/open1346906329006.html
android实现View的渐隐渐现功能就用到了动画Animation
首先在res目录下新建anim文件夹,然后再anim文件夹下新建xml文件gradually.xml
该xml文件主要定义实现渐变的方式
1 | <? xml version = "1.0" encoding = "utf-8" ?> |
2 | < set xmlns:android = "http://schemas.android.com/apk/res/android" > |
3 | < alpha |
4 | android:fromAlpha = "0.0" |
5 | android:toAlpha = "1.0" |
6 | android:duration = "2000" |
7 | /> |
8 | |
9 | </ set > |
alpha代表透明度,0.0是完全透明,1.0是完全不透明,duration指过度时间
其中还可以设定其他值,rotate代表旋转
scale代表缩放
translate代表水平位置移动
在代码中首先要加载该动画:Animation animation = AnimationUtils.loadAnimation(Context, R.anim.gradually);
然后设置View启动动画:view.startAnimation(animation);