示例

代码
alpha「anim文件」
<?xml version="1.0" encoding="utf-8"?>
<!--透明动画-->
<alpha android:repeatMode="reverse"
android:repeatCount="1"
android:duration="3000"
android:fromAlpha="1.0"
android:toAlpha="0.0"
xmlns:android="http://schemas.android.com/apk/res/android">
</alpha>
引入动画
//给按键添加动画
//1.找到动画文件
Button button=(Button) findViewById(R.id.btn);
//2.找到动画文件
Animation anim= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.alpha);
//3.给控件添加动画效果
button.startAnimation(anim);
AndroidXML透明动画实现
该文章展示了如何在Android中创建一个XML定义的透明度动画(alpha),动画从完全不透明(1.0)渐变到完全透明(0.0),并在3秒内重复一次。通过AnimationUtils加载此动画,并将其应用到Button控件上,实现按键的动画效果。
488





