public static void fadeIn(View view, float startAlpha, float endAlpha, long duration) {
if (view.getVisibility() == View.VISIBLE) return;
view.setVisibility(View.VISIBLE);
Animation animation = new AlphaAnimation(startAlpha, endAlpha);
animation.setDuration(duration);
view.startAnimation(animation);
}
public static void fadeIn(View view) {
fadeIn(view, 0F, 1F, 400);
// We disabled the button in fadeOut(), so enable it here.
view.setEnabled(true);
}
public static void fadeOut(View view) {
if (view.getVisibility() != View.VISIBLE) return;
// Since the button is still clickable before fade-out animation
// ends, we disable the button first to block click.
view.setEnabled(false);
Animation animation = new AlphaAnimation(1F, 0F);
animation.setDuration(400);
view.startAnimation(animation);
view.setVisibility(View.GONE);
}
Android View显示隐藏渐变动画
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 首先来看一个UI动效图。 我所实现的效果如下:Watch on YouTube 使用方法 为了使用起来简单,我将动...
- 效果图: 代码: 动画工具类 package test.j.com.test.utils; import andr...
- 我们知道属性动画要设置get、set 方法,但是有时不好设置,因此我们找新方法。 /** * Created by...