
我一直在尝试使用圆形的揭示动画从我的活动中插入和删除片段.我发现这个演示仓库here正是这样做的.我所做的唯一更改是在单击按钮时删除了片段,而不是让片段触及了监听器.
问题是,使用按钮删除后,动画结束时,我看到片段闪烁了一秒钟.如果我使用ontouch侦听器删除片段,则不会发生闪烁:YouTube link
一些观察:
-如果我在移动设备上运行代码,则只有在我使用按钮删除片段时,才会发生闪烁.调用onFragmenttouch时不会发生闪烁.
-如果我正在模拟器上运行它,那么我可以看到它同时闪烁,按下按钮和触摸片段.
为简化起见,我的onFragmenttouch侦听器只是调用一个实际上删除了片段的函数remove.该按钮在其XML中也调用了相同的功能.
我不明白为什么会这样.代码供参考.
在主要活动中添加片段:
public voID addFragment(VIEw v) { int randomcolor = color.argb(255, (int)(Math.random() * 255), (int)(Math.random() * 255), (int)(Math.random() * 255)); mfragment = CircularRevealingFragment.newInstance(20, 20, randomcolor); getFragmentManager().beginTransaction().add(R.ID.container, mfragment).commit(); }也在主要活动中删除片段的功能:
public voID remove(VIEw v){ Animator unreveal = mfragment.prepareUnrevealAnimator(0, 0); unreveal.addListener(new Animator.AnimatorListener() { @OverrIDe public voID onAnimationEnd(Animator animation) { getFragmentManager().beginTransaction().remove(mfragment).commit(); } //hIDing other overrIDden function. }); unreveal.start(); }CircularRevealingFragment非常简单,几乎所有内容都与该github项目中的相同.未公开的动画师:
public Animator prepareUnrevealAnimator(float cx, float cy) { int radius = getEnclosingCircleRadius(getVIEw(), (int)cx, (int)cy); Animator anim = VIEwAnimationUtils.createCircularReveal(getVIEw(), (int) cx, (int) cy, radius, 0); anim.setInterpolator(new AccelerateInterpolator(2f)); anim.setDuration(1000); return anim; }谁能解释视频中显示的行为?
解决方法:
我认为主要问题是提交的FragmentTransaction异步执行.如果要立即执行,请使用getFragmentManager().executePendingTransactions().
总结以上是内存溢出为你收集整理的android-删除和动画结束后片段闪烁全部内容,希望文章能够帮你解决android-删除和动画结束后片段闪烁所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)