当按下按钮时,我想要发生两件事 1.两张图像应该一遍又一遍地播放,给它一个动画和静态的外观。 2.循环中的声音。如何在未按下按钮时停止动画
当按钮未按下且手指向上时 1.声音应停止 2.动画应停止。
我用现在的方法显示在代码:
package com.example.newanimation;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;
public class MainActivity extends Activity {
AnimationDrawable rocketAnimation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView rocketImage = (ImageView) findViewById(R.id.imageView1);
rocketImage.setBackgroundResource(R.drawable.ball_animation);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
rocketAnimation.start();
return true;
}
return super.onTouchEvent(event);
}
}
和XML就像
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/ball01" android:duration="200" />
<item android:drawable="@drawable/ball02" android:duration="200" />
<item android:drawable="@drawable/ball03" android:duration="200" />
</animation-list>
我保持的android:单稳= “假”>而非“真正的“,因为我希望动画不停地播放,直到按钮被按下,但是当手指从按钮向上时,我需要它停止。
的方法取消();未定义为动画可绘制:/ – 2015-02-07 07:18:26
将其更改为'stop()':D – Hemanth 2015-02-07 07:21:55
那里完成了:/ – 2015-02-07 07:23:07