我正在制作一个包含帧动画的android项目。我的动画在4.0中运行良好,但在2.2中没有显示。有什么方法可以让它在2.2 / 2.3中运行吗?任何2.2的工作代码片段都会很棒。
如果需要,可以发布我的代码。
编辑: 这是我的工作代码
public class FrameAnimationExample extends Activity {
AnimationDrawable animation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnStart = (Button) findViewById(R.id.btnStart);
final ImageView imgView = (ImageView)findViewById(R.id.img);
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startAnimation();
}
});
imgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
class Starter implements Runnable {
public void run() {
animation.start();
}
}
private void startAnimation(){
animation = new AnimationDrawable();
animation.addFrame(getResources().getDrawable(R.drawable.hud_bubble_fill_line), 100);
animation.addFrame(getResources().getDrawable(R.drawable.hud_bubble_fill), 100);
animation.addFrame(getResources().getDrawable(R.drawable.medal_brown), 100);
animation.addFrame(getResources().getDrawable(R.drawable.medal_silver), 100);
animation.addFrame(getResources().getDrawable(R.drawable.medal_gold), 100);
animation.setOneShot(true);
ImageView imageView = (ImageView) findViewById(R.id.img);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(80, 90);
params.alignWithParent = true;
params.addRule(RelativeLayout.CENTER_IN_PARENT);
imageView.setLayoutParams(params);
imageView.setImageDrawable(animation);
imageView.post(new Starter());
}
}
答案 0 :(得分:0)
// animation call
ImageView img = (ImageView) findViewById(R.id.img);
img.post(animateMe);
final Runnable animateMe = new Runnable() {
@Override
public void run() {
ImageView imageView = (ImageView) findViewById(R.id.img);
imageView.setBackgroundResource(R.anim.img_animation);
AnimationDrawable frameAnimation = (AnimationDrawable) imageView.getBackground();
frameAnimation.start();
}
};
和img_animation.xml一样:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selected"
android:oneshot="true">
<!-- ur anim images here -->
<item android:drawable="@drawable/hud_bubble_fill_line" android:duration="100" />
<item android:drawable="@drawable/hud_bubble_fill" android:duration="100" />
<!-- and so on -->
</animation-list>