开发者社区> 问答> 正文

android动画问题,XML写闪烁,动态代码写为什么不闪烁?

animationSet1 = new AnimationSet(true);
 animationSet2 = new AnimationSet(true);
 image2.setVisibility(View.VISIBLE);
 Animation animation1 = AnimationUtils.loadAnimation(getActivity(), R.anim.tttxt_fragment_layout_imageview1_anim);
 animationSet1.addAnimation(animation1);
 Animation animation2 = AnimationUtils.loadAnimation(getActivity(), R.anim.tttxt_fragment_layout_imageview2_anim);
 animationSet2.addAnimation(animation2);
 image1.startAnimation(animationSet1);
 image2.startAnimation(animationSet2);
 tttxt_fragment_layout_imageview1_anim:


 android:duration="2000"
 android:fillAfter="true"
 android:fromXDelta="0%"
 android:toXDelta="-100%" />

 tttxt_fragment_layout_imageview2_anim:

 android:duration="2000"
 android:fillAfter="true"
 android:fromXDelta="100%"
 android:toXDelta="0%" />

上面这种方法加载动画为什么闪烁?

下面这样就不闪烁,这不是一样吗?:

 AnimationSet animationSet1 = new AnimationSet(true);
 AnimationSet animationSet2 = new AnimationSet(true);
 image2.setVisibility(View.VISIBLE);
 TranslateAnimation ta = new TranslateAnimation(
 Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
 -1f, Animation.RELATIVE_TO_SELF, 0f,
 Animation.RELATIVE_TO_SELF, 0f);
 ta.setDuration(2000);
 animationSet1.addAnimation(ta);
 animationSet1.setFillAfter(true);
 ta = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 1.0f,
 Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF,
 0f, Animation.RELATIVE_TO_SELF, 0f);
 ta.setDuration(2000);
 animationSet2.addAnimation(ta);
 animationSet2.setFillAfter(true);
 //iamgeView 出去 imageView2 进来
 image1.startAnimation(animationSet1);
 image2.startAnimation(animationSet2);

展开
收起
爵霸 2016-06-01 14:59:20 2958 0
1 条回答
写回答
取消 提交回答
  • 两种方法加载是一样的,就是不知道你所谓的闪烁效果是怎样的?(吐槽一下,你就一个动画,干嘛要用set?)

    2019-07-17 19:23:22
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载