我已经创建了一个包含图像视图和web视图的布局。web视图被设置为默认可见性为gone。当活动启动时,它首先显示图像视图,当web视图完成加载其url时,它将自己标记为可见,而图像视图将标记为隐藏。
当显示图像视图时,我希望它反复旋转,只是为了增加一点活力。
我以前从来没有在Android上做过动画,当我向互联网询问时,我找到的所有帖子都没有帮助;因此,我回到了SO寻求帮助。
所以如果我从这个开始...
final ImageView splash = (ImageView)findViewById(R.id.splash);
如何创建重复旋转动画并将其应用于ImageView?
再次感谢!
发布于 2010-01-09 21:20:56
使用RotateAnimation
,将轴心点设置到图像的中心。
RotateAnimation anim = new RotateAnimation(0f, 350f, 15f, 15f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(700);
// Start animating the image
final ImageView splash = (ImageView) findViewById(R.id.splash);
splash.startAnimation(anim);
// Later.. stop the animation
splash.setAnimation(null);
发布于 2010-01-09 21:08:00
您也可以简单地使用旋转动画功能。它在ImageView上运行特定的动画,持续一段预定的时间。
Animation rotate = AnimationUtils.loadAnimation([context], R.anim.rotate_picture);
splash.startAnimation(rotate);
然后在res/anim中创建一个名为rotate_picture的动画XML文件,其内容如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:duration="5000"
android:pivotX="50%"
android:pivotY="50%">
</rotate>
</set>
不幸的是,它只能运行一次。你需要一个循环,让它在等待的时候重复动画。我做了一点实验,让我的程序陷入了无限循环,所以我不确定最好的方法。编辑:Christopher的回答提供了如何让它正确循环的信息,所以删除我关于独立线程的糟糕建议!
发布于 2010-01-09 12:28:53
一种方式--把你的图像分成N个,每次稍微旋转一下。我想说5个就足够了。然后在drawable中创建类似这样的东西
<animation-list android:id="@+id/handimation" android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/progress1" android:duration="150" />
<item android:drawable="@drawable/progress2" android:duration="150" />
<item android:drawable="@drawable/progress3" android:duration="150" />
</animation-list>
代码开始
progress.setVisibility(View.VISIBLE);
AnimationDrawable frameAnimation = (AnimationDrawable)progress.getDrawable();
frameAnimation.setCallback(progress);
frameAnimation.setVisible(true, true);
代码停止
AnimationDrawable frameAnimation = (AnimationDrawable)progress.getDrawable();
frameAnimation.stop();
frameAnimation.setCallback(null);
frameAnimation = null;
progress.setVisibility(View.GONE);
更多here
https://stackoverflow.com/questions/2032304
复制相似问题