首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >安卓ImageView动画

安卓ImageView动画
EN

Stack Overflow用户
提问于 2010-01-09 12:08:49
回答 7查看 161.8K关注 0票数 63

我已经创建了一个包含图像视图和web视图的布局。web视图被设置为默认可见性为gone。当活动启动时,它首先显示图像视图,当web视图完成加载其url时,它将自己标记为可见,而图像视图将标记为隐藏。

当显示图像视图时,我希望它反复旋转,只是为了增加一点活力。

我以前从来没有在Android上做过动画,当我向互联网询问时,我找到的所有帖子都没有帮助;因此,我回到了SO寻求帮助。

所以如果我从这个开始...

代码语言:javascript
复制
    final ImageView splash = (ImageView)findViewById(R.id.splash);

如何创建重复旋转动画并将其应用于ImageView?

再次感谢!

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2010-01-09 21:20:56

使用RotateAnimation,将轴心点设置到图像的中心。

代码语言:javascript
复制
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);
票数 108
EN

Stack Overflow用户

发布于 2010-01-09 21:08:00

您也可以简单地使用旋转动画功能。它在ImageView上运行特定的动画,持续一段预定的时间。

代码语言:javascript
复制
Animation rotate = AnimationUtils.loadAnimation([context], R.anim.rotate_picture);
splash.startAnimation(rotate);

然后在res/anim中创建一个名为rotate_picture的动画XML文件,其内容如下:

代码语言:javascript
复制
<?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的回答提供了如何让它正确循环的信息,所以删除我关于独立线程的糟糕建议!

票数 26
EN

Stack Overflow用户

发布于 2010-01-09 12:28:53

一种方式--把你的图像分成N个,每次稍微旋转一下。我想说5个就足够了。然后在drawable中创建类似这样的东西

代码语言:javascript
复制
<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> 

代码开始

代码语言:javascript
复制
progress.setVisibility(View.VISIBLE);
AnimationDrawable frameAnimation = (AnimationDrawable)progress.getDrawable();
frameAnimation.setCallback(progress);
frameAnimation.setVisible(true, true);

代码停止

代码语言:javascript
复制
AnimationDrawable frameAnimation = (AnimationDrawable)progress.getDrawable();
frameAnimation.stop();
frameAnimation.setCallback(null);
frameAnimation = null;
progress.setVisibility(View.GONE);

更多here

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2032304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档