setAnimation首次notset是无效的主机名,第二次才会显示动画怎么回事

为何怎么设置setFillAfter都没有效果呢?【android开发吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:119,811贴子:
为何怎么设置setFillAfter都没有效果呢?收藏
本人菜鸟一个,刚刚接触anim,想把动画效果停留在最后一帧,为何这么设置都不行呢?下面是代码,望热心人帮看看:myanimation = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);myanimation.setFillAfter(true);myanimation.setFillEnabled(true);myanimation.setDuration(3000);myanimation.setRepeatCount(10);img.setAnimation(myanimation);stop.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View arg0) {//img.clearAnimation();myanimation.cancel();}});
安卓开发技术新,市场占有率大!慕课网专业讲师全力打造Android入门到精通课程!系统化学习,精心服务,结合真实开发案例,提升学习效果,带你快速入行!直达名企!
我也遇到了。。楼主有解不。。?求带求超神。。
我也是菜鸟,我把自己解决的个大家看一下,仅供参考不需骂人!!首先我不是用rotateAnimation中自带的属性让它停的,我是算出它在两次点击中的角度,然后进行matrix进行旋转的。
要求:1)必需是匀速旋转;
2)旋转中心尽量是图片的中心;
代码如下: public void onClick(View arg0) {
b++; if(b==1){ timeend=System.currentTimeMillis();//第一次点击的初试时间 timestart= System.out.println(&----timeend:&+timeend+&--timendstart:&+timestart); ic.startAnimation(an); }else if(b==2){ b=0; timeend=System.currentTimeMillis();//第二次点击的结束时间 time=timeend- float s=360/1000f;//旋转速度 float f=time*s; //旋转角度(关键就是求出它) System.out.println(&----time:&+time);//然后是matrix旋转操作 Matrix m=new Matrix(); m.postRotate(f, ic.getResources().getDisplayMetrics().widthPixels/2,ic.getResources().getDisplayMetrics().heightPixels/2); Bitmap bitm=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher); Bitmap bit=Bitmap.createBitmap(bitm, 0,0,bitm.getWidth(), bitm.getHeight(), m,true); translateAnimation.cancel();
ic.setImageBitmap(bit);//添加旋转后的图片 ic.clearAnimation();
timeend=0l;//第二次点击之后至零 timestart=0l; }}};
自己转了一会,发现大小还是不好控制。。。
哈哈哈。。抱歉。。自己测了一会少了点东西float f+=time*s; //旋转角度 要不停的叠加,否则计算时,总是从零度开始。还可以这样整: if(f&=360){
f=f%360;}else{
float f+=time*s;}
自己慢慢试吧。。。
哈哈。。写一点挤一点出来:又发现问题了if(f&=360){f=f%(360*(int)(time/1000));//还要乘以转的总圈数}else{
f+=time*s;}
登录百度帐号推荐应用AnimationSet scaleanimationSet = new AnimationSet(true);
ScaleAnimation scaleAnimation = new ScaleAnimation(1f,2f,1f,2f,Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f);
scaleAnimation.setRepeatCount(3);
scaleanimationSet.addAnimation(scaleAnimation);
scaleanimationSet.setStartOffset(2000);
scaleanimationSet.setDuration(2000);
scaleanimationSet.setFillAfter(true);
imageView.startAnimation(scaleanimationSet);
如代码所示,必须设置ScaleAnimation的 RepeatCount才有效,而AnimationSet.setRepeatCount无效!
本文已收录于以下专栏:
相关文章推荐
对于Animation动画,如果是通过AnimationUtils.loadAnimation导入的xml文件则不能使用setRepeatMode 和setRepeatCount方法,这两个属性必须在...
在写一个小动画时发现AnimatorSet没有setRepeatCount()与setRepeatMode()方法,但是动画效果又要求重复执行,这里提供的解决方法时:
给动画集合中的子动画设置set...
本篇只要讲解iOS中动画的使用.
Animtion主要分为两类:UIView动画和CoreAnimation动画。
UIView动画有UIView属性动画,UIViewBlock动画,UIView...
第一步在storyboard中创建一个UIIimageView对象.
@property (strong,
nonatomic) IBOutlet
UIImageView *tomImageVi...
animationImages是数组类型,该数组必须包含的UIImage对象。您可以使用相同的图像对象多次在阵中。
例如:将一系列帧添加到一个数组里面,然后设置animation一系列属性,如动...
以 xml的形式定义了动画,但是没有起作用
我们都知道,一个动画实例可以有两种方式来实现:
1、纯Java代码RotateAnimation rotateAnimation = new RotateAnimation(0,360,
Animations分两类:
第一类:渐变的(Tweened): 淡入淡出(Alpha),旋转(Rotate),移动(Translate),缩放(Scale);
第二类:Frame-by-Fram...
他的最新文章
讲师:李江龙
讲师:司徒正美
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)查看: 22033|回复: 7
AnimationSet中动画的执行顺序问题
该用户从未签到主题帖子e币
没有eoe的账号,级别还太低,出门如何吹牛逼?
才可以下载或查看,没有帐号?
本帖最后由 dingxu_ren 于
13:23 编辑
我想做个动画,界面上一个按钮,先向右侧移动一点,然后向左侧移出屏幕,最后从右侧移动回来
下面是代码:
private void doTranslateAnimation(View view) {
& && &&&AnimationSet set = new AnimationSet(true);
& && &&&TranslateAnimation readyAnim = new TranslateAnimation(
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0f,
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0.2f,
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0f,
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0f);
& && &&&readyAnim.setDuration(100);
& && &&&set.addAnimation(readyAnim);
& && &&&TranslateAnimation outAnim = new TranslateAnimation(
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0,
& && &&&TranslateAnimation.RELATIVE_TO_PARENT, -1,
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0,
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0);
& && &&&outAnim.setDuration(500);
& && &&&outAnim.setStartOffset(100);
& && &&&set.addAnimation(outAnim);
& && &&&TranslateAnimation inAnim = new TranslateAnimation(
& && &&&TranslateAnimation.RELATIVE_TO_PARENT, 1,
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0,
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0,
& && &&&TranslateAnimation.RELATIVE_TO_SELF, 0);
& && &&&inAnim.setDuration(500);
& && &&&inAnim.setStartOffset(600);
& && &&&set.addAnimation(inAnim);
& && &&&view.startAnimation(set);
}复制代码
但运行的结果不对,动画的执行顺序有问题,首先是按钮消失,然后从屏幕右侧出现,向左侧移动出屏幕。
调试发现,如果不加第三个动画,执行顺序就没问题。
麻烦大家看下是哪出了问题。
签到天数: 14 天连续签到: 1 天[LV.3]偶尔看看II主题帖子e币
& & & & public void doTranslateAnimation(final View view) {
& & & & & & & & AnimationSet set = new AnimationSet(true);
& & & & & & & & TranslateAnimation readyAnim = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0f,
& & & & & & & & & & & & & & & & TranslateAnimation.RELATIVE_TO_SELF, 0.2f,
& & & & & & & & & & & & & & & & TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.RELATIVE_TO_SELF, 0f);
& & & & & & & & readyAnim.setDuration(100);
& & & & & & & & set.addAnimation(readyAnim);
& & & & & & & & TranslateAnimation outAnim = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0,
& & & & & & & & & & & & & & & & TranslateAnimation.RELATIVE_TO_PARENT, -1,
& & & & & & & & & & & & & & & & TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);
& & & & & & & & outAnim.setDuration(500);
& & & & & & & & outAnim.setStartOffset(100);
& & & & & & & & outAnim.setAnimationListener(new Animation.AnimationListener() {
& & & & & & & & & & & &
& & & & & & & & & & & & @Override
& & & & & & & & & & & & public void onAnimationStart(Animation animation) {
& & & & & & & & & & & & & & & & // TODO Auto-generated method stub
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & & & & &
& & & & & & & & & & & & @Override
& & & & & & & & & & & & public void onAnimationRepeat(Animation animation) {
& & & & & & & & & & & & & & & & // TODO Auto-generated method stub
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & & & & &
& & & & & & & & & & & & @Override
& & & & & & & & & & & & public void onAnimationEnd(Animation animation) {
& & & & & & & & & & & & & & & & TranslateAnimation inAnim = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_PARENT, 1,
& & & & & & & & & & & & & & & & & & & & & & & & TranslateAnimation.RELATIVE_TO_SELF, 0,
& & & & & & & & & & & & & & & & & & & & & & & & TranslateAnimation.RELATIVE_TO_SELF, 0, TranslateAnimation.RELATIVE_TO_SELF, 0);
& & & & & & & & & & & & & & & & inAnim.setDuration(500);
& & & & & & & & & & & & & & & & view.clearAnimation();
& & & & & & & & & & & & & & & & view.startAnimation(inAnim);
& & & & & & & & & & & & & & & &
& & & & & & & & & & & & }
& & & & & & & & });
& & & & & & & &
& & & & & & & &
& & & & & & & & set.addAnimation(outAnim);
& & & & & & & &
& & & & & & & & view.startAnimation(set);
是的,谢谢。那为什么前两个能放在一个set里,而最后一个得在前两个动画播放完成后再播放,才能正确显示?&
这应该是你想要的效果吧&
签到天数: 14 天连续签到: 1 天[LV.3]偶尔看看II主题帖子e币
public void doTranslateAnimation(final View view) {
& & & & & & & & AnimationSet set = new AnimationSet(true);
& & & & & & & &&&...
这应该是你想要的效果吧
该用户从未签到主题帖子e币
public void doTranslateAnimation(final View view) {
& & & & & & & & AnimationSet set = new AnimationSet(true);
& & & & & & & &&&...
是的,谢谢。那为什么前两个能放在一个set里,而最后一个得在前两个动画播放完成后再播放,才能正确显示?
最后一个动画 ,开始时候就已经右移了,所以才会出现消失效果&
签到天数: 14 天连续签到: 1 天[LV.3]偶尔看看II主题帖子e币
是的,谢谢。那为什么前两个能放在一个set里,而最后一个得在前两个动画播放完成后再播放,才能正确显示 ...
最后一个动画 ,开始时候就已经右移了,所以才会出现消失效果
是不是不论动画设置多长时间的offset,在startAnimation后,都会把view置为动画的初始状态?
如TranslateAnimation的fromX/FromY,
AlphaAnimation的fromAlpha。&
该用户从未签到主题帖子e币
最后一个动画 ,开始时候就已经右移了,所以才会出现消失效果
是不是不论动画设置多长时间的offset,在startAnimation后,都会把view置为动画的初始状态?
如TranslateAnimation的fromX/FromY,&&AlphaAnimation的fromAlpha。
签到天数: 14 天连续签到: 1 天[LV.3]偶尔看看II主题帖子e币
是不是不论动画设置多长时间的offset,在startAnimation后,都会把view置为动画的初始状态?
如Translate ...
谢谢您的耐心解答,太感谢了&
该用户从未签到主题帖子e币
谢谢您的耐心解答,太感谢了
推荐阅读热门话题
61887420384328284284261252226218210205201192715
半小时前昨天&23:37昨天&14:09昨天&10:52昨天&10:20昨天&09:37前天&23:58前天&16:58前天&16:413&天前3&天前4&天前4&天前4&天前4&天前4&天前
Powered by与animationset() Android动画
扫码加入我们
与animationset() Android动画
OK here's the problem
i have an ImageView in my activity, here's what it looks in main.xml:
&ImageView
android:id="@+id/ic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_gravity="center_horizontal"/&
I want this image to move -200(left) and then to 100(right) and then back to 0 with bouncing effect.
I've implement this with my code:
as = new AnimationSet(true);
as.setFillEnabled(true);
as.setInterpolator(new BounceInterpolator());
TranslateAnimation ta = new TranslateAnimation(-300, 100, 0, 0);
ta.setDuration(2000);
as.addAnimation(ta);
AnimationSet sa = new AnimationSet(true);
sa.setFillEnabled(true);
sa.setInterpolator(new DecelerateInterpolator());
TranslateAnimation ta2 = new TranslateAnimation(100, 0, 0, 0);
ta2.setDuration(2000);
sa.addAnimation(ta2);
as.addAnimation(sa);
you can see at the code the X transition that i want (-300,100) then (100, 0)
however, the image doesn't move like it should, instead it just stop at 100 and then bouncing...
hmmm...., do you guys know what is wrong or what should i do to accomplish this?
If I'm not mistaking, you're shooting for a sequence of animations.
Interestingly, once you start an AnimationSet, all the animations added are ran simultaneously
therefore you need to setStartOffset(long offSet) for each animation that follows the first animation.
Maybe something like this will work...
as = new AnimationSet(true);
as.setFillEnabled(true);
as.setInterpolator(new BounceInterpolator());
TranslateAnimation ta = new TranslateAnimation(-300, 100, 0, 0);
ta.setDuration(2000);
as.addAnimation(ta);
TranslateAnimation ta2 = new TranslateAnimation(100, 0, 0, 0);
ta2.setDuration(2000);
ta2.setStartOffset(2000); // allowing 2000 milliseconds for ta to finish
as.addAnimation(ta2);
日28分47秒
I suggest you to use ObjectAnimator. It is very easy to implement your case. Your animation may look like this:
ObjectAnimator animator1 = ObjectAnimator.ofFloat(targetView, "translationX", -200f);
animator1.setRepeatCount(0);
animator1.setDuration(1000);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(targetView, "translationX", 100f);
animator2.setRepeatCount(0);
animator2.setDuration(1000);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(targetView, "translationX", 0f);
animator3.setRepeatCount(0);
animator3.setDuration(1000);
//sequencial animation
AnimatorSet set = new AnimatorSet();
set.play(animator1).before(animator2);
set.play(animator2).before(animator3);
set.start();
If you are not familior with ObjectAnimator, you can check this android example tutorial:
日28分47秒
Something like this is very easy in 3.0 and above.
Here are two links that I used to accomplish something similar.
日28分47秒
& 2017 内容协议}

我要回帖

更多关于 android setprop 无效 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信