AlphaAnimation写在oncreate没效果
来源:互联网 发布:暗黑黎明挂机软件 编辑:程序博客网 时间:2024/04/30 19:31
今天写demo的时候用到了AlphaAnimation
能做出一种透明动画渐变效果
有一个xml文件里有个<ImageView>
一个.java文件
public class aa extends Activity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
imageView = (ImageView) View.inflate(this, R.layout.activity_splash, null);
setContentView(imageView);
//渐变
AlphaAnimation alphaAnimation = new AlphaAnimation(0.3f, 1.0f);
//动画持续时间
alphaAnimation.setDuration(2000);
alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
//动画执行前
@Override
public void onAnimationStart(Animation animation) {
}
//动画播放完成后调用的函数
@Override
public void onAnimationEnd(Animation animation) {
startMainActivity();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
//设置动画效果到imageview
imageView.startAnimation(alphaAnimation);
}
然后 然后问题来了 这个Imageview并没有动画效果
最后在师兄的帮助下 才明白这个动画效果不能放在oncreate()里执行
至于原因可能是因为
在OnCreate()中AnimationDrawable还没有完全的与ImageView绑定,
在OnCreate()中启动动画,就只能看到第一张图片。
然后就有了解决方案
方法—:使用Handle(http://www.bkjia.com/gjrj/798077.html 其实不知道有没效果找为什么不能在onCreate使用动画找到的)
方法二:
吧代码写在onWindowFocusChanged()里 好像说这个很重要(http://blog.csdn.net/pi9nc/article/details/9237031)
反正我第一次见。吧动画效果剪切到里面。
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
//透明动画效果
AlphaAnimation alphaAnimation = new AlphaAnimation(0.3f,1.0f);
//设置动画时间
alphaAnimation.setDuration(3000);
//加载动画效果到控件
imageView.startAnimation(alphaAnimation);
//
alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
public void onAnimationStart(Animation animation) {
}
public void onAnimationEnd(Animation animation) {
startMainActivity();
}
public void onAnimationRepeat(Animation animation) {
}
});
}
搞定。
- AlphaAnimation写在oncreate没效果
- AlphaAnimation动画效果
- AlphaAnimation
- AlphaAnimation
- AndroidUI 视图动画-透明动画效果 (AlphaAnimation)
- 在splash页面添加AlphaAnimation透明度渐变动画效果
- frame animation不可以直接写在oncreate方法中
- 设置setVisibility没效果
- StatusBarHidden 没效果
- 刷新实体没效果
- OnCreate
- OnCreate
- oncreate
- onCreate
- onCreate
- Android 动画之AlphaAnimation应用详解(透明度动画效果)转载
- Android各种动画效果ScaleAnimation,AlphaAnimation,TranslateAnimation,RotateAnimation(文章结尾有代码)
- AlphaAnimation 、AnimationDrawable
- Unsafe与CAS
- Uncaught TypeError: ((m.event.special[e.origType] || (intermediate value)).handle || e.handler).appl
- GUI中各种布局
- JavaEE 搜索解决问题集合---会不断更新的
- Hadoop2.6.0运行mapreduce之推断(speculative)执行(下)
- AlphaAnimation写在oncreate没效果
- 鸢尾花分类——神经网络详解
- 《Linux C》04 串口编程总结
- 【BZOJ3876】[Ahoi2014]支线剧情【最小费用最大流】
- SunShine学习总结
- Android-SubMenu子菜单
- 【剑指offer-Java版】37两个链表的第一个公共结点
- (冲突)十大Intellij IDEA快捷键
- MySQL存储过程详解 mysql 存储过程