我有一个 imageView,我想以不可见的方式启动。单击某个按钮后,我想要将图像动画化到视图中,然后我希望它保持 alpha 1。我该怎么做?到目前为止还没有运气。如果我在 xml 中将 alpha 设置为 0,那么我将永远看不到图像。如果我没有在 xml 中设置 alpha,则图像始终可见,并且当单击按钮时,它会从 0 到 1 alpha 进行动画处理。
这是我的动画代码。
AlphaAnimation animation1 = new AlphaAnimation(0.0f, 1.0f);
animation1.setDuration(1000);
animation1.setStartOffset(5000);
animation1.setFillAfter(true);
tokenBtn.startAnimation(animation1);
在MainActivity.java中添加
public void blink(View view) {
ImageView image = (ImageView) findViewById(R.id.imageView);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
image.startAnimation(animation1);
}
在res>anim文件夹中创建名为blink.xml的文件并添加此代码
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="--YOUR DURATION--"
android:repeatMode="reverse"
android:repeatCount="0"/>
</set>
并确保按钮上的 onClick 函数名为眨眼
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)