android - 使用可绘制对象动画图像

标签 android animation imageview drawable

我是 andriod 的新手,如果有人能帮助我,我将不胜感激。 我正在尝试为一系列图像(图片)制作动画。我读了一些关于它的内容,似乎一个很好的方法就是使用可绘制对象。我的代码如下所示:

我有一个 animation.xml 文件:

<animation-list xmlns:android = "http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/im1" android:duration="200" />
<item android:drawable="@drawable/im2" android:duration="200" /> </animation-list>

我在 main.xml 中定义了一个 ImageView :

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget32"
android:layout_width="fill_parent"
android:layout_height="fill_parent"> <ImageView
android:id="@+id/picView"
android:layout_width="500px"
android:layout_height="200px"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"> </ImageView> </RelativeLayout>

最后,在我的 Activity 中,我使用可绘制对象来制作动画。像这样:

public class animatePic extends Activity

{

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    ImageView image = (ImageView) findViewById(R.id.picView);
    image.setVisibility(ImageView.VISIBLE);
    image.setBackgroundResource(R.drawable.animation);
    AnimationDrawable imAnimate = (AnimationDrawable)image.getBackground();
    imAnimate.start();

}

我的问题是我只得到第一张图片,而不是无限循环的图片。 有人能帮忙吗??我正在 android 2.1 平台上进行开发(这与此有什么关系吗?:))。

非常感谢

李皮

最佳答案

我认为您在这里遇到的唯一问题是您无法在 onCreate 方法中启动 AnimationDrawable。 更多解释在这里:http://developer.android.com/guide/topics/graphics/drawable-animation.html , 在文档的末尾...

关于android - 使用可绘制对象动画图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5701245/

相关文章:

android - 在 sleep 模式下使用音量按钮(音乐播放器风格)

java - 为什么我不能构建 apk 而不是 aar?

ios - 动画 UITextView 增加或减少数字的值

java - 无法在通过 Canvas 编辑 ImageView 的类中使用 TouchEvent

android imageview默认缩放级别

android - 提供的Android SDK图标可以设置颜色吗?

android - Cordova 构建到 Android 错误

javascript - jQuery UI 模式对话框覆盖淡出

jquery - 如何使用 jQuery 同步 CSS3 动画事件和事件监听器

android 在 ListView 中调整图像大小