gpt4 book ai didi

java - 使用动画绘制显示动画

转载 作者:行者123 更新时间:2023-12-01 13:48:28 26 4
gpt4 key购买 nike

我在 Android 开发者网站上读到了如何将图像序列转换为动画的方法。但没有显示任何内容。无论是图像还是动画。

package org.example.anim;

import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.widget.ImageView;

public class MainActivity extends Activity {

AnimationDrawable frameAnimation;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);

// Get the background, which has been compiled to an AnimationDrawable
frameAnimation = (AnimationDrawable) img.getBackground();

// Start the animation (looped playback by default).
}

public void onWindowFocusChanged()
{

frameAnimation.start();
}


}

最佳答案

    ImageView progressSpinner = (ImageView) findViewById(R.id.progressSpinner);

// Set the background of the image - In this case an animation
// (/res/anim folder)
progressSpinner.setBackgroundResource(R.anim.progress_animation);
// Get the image background and attach the AnimationDrawable to it.
progressAnimation = (AnimationDrawable) progressSpinner.getBackground();
progressAnimation.start();

将图像从drawable移动到anim文件夹并在onCreate中尝试此代码。

关于java - 使用动画绘制显示动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20160530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com