私は、Androidアプリでどのようにアニメーションを開始したり停止したりできるかを把握しようとしています。アニメーションの開始と停止
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
stopOneButton = (Button) findViewById(R.id.buttonStopOne);
stopTwoButton = (Button) findViewById(R.id.buttonStopTwo);
stopThreeButton = (Button) findViewById(R.id.buttonStopThree);
startButton = (Button) findViewById(R.id.buttonStart);
firstImage = (ImageView) findViewById(R.id.imageView1);
firstImage.setBackgroundResource(R.drawable.spin_animation);
frameAnimation = new AnimationDrawable();
AnimationDrawable frameAnimation = (AnimationDrawable) firstImage.getBackground();
// frameAnimation.start();
firstImage.post(new Starter());
stopOneButton.setOnClickListener(this);
stopTwoButton.setOnClickListener(this);
stopThreeButton.setOnClickListener(this);
startButton.setOnClickListener(this);
}
class Starter implements Runnable {
public void run() {
frameAnimation.start();
}
}
これはかなり私が持っているすべてのもの、およびIM機能に任意のボタンを結合することなく、ゼロから始めるですが、画像は、すべての周りの回転していません。
これは、描画可能なため、私のXMLファイルです:ボタンのコード
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/image1" android:duration="500" />
<item android:drawable="@drawable/image2" android:duration="500" />
<item android:drawable="@drawable/image3" android:duration="500" />
<item android:drawable="@drawable/image4" android:duration="500" />
</animation-list>
より:
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.buttonStopOne:
break;
case R.id.buttonStopTwo:
break;
case R.id.buttonStopThree:
break;
case R.id.buttonStart:
frameAnimation.start();
break;
}
}
誰もがイムが間違っているのかを決定することはできますか?
私は少し混乱することを見つけるには、 'frameAnimation.start()がない;'私のアニメーションを開始しませんか? – JavaCake
アニメーションを開始する別の方法は、 'View'で' setAnimation'を呼び出し、アニメーションを渡し、アニメーション自体で 'start()'を呼び出すことです。したがって、あなたの場合は、セットのどこかでfirstimage.setAnimation(frameAnimation);となります。そして、 'frameAnimation.start()'と呼ばれるアニメーションを再生したいとき。アニメーションがどのビューも参照していないことがアニメーション化されていない理由はほとんどわかりません。 – DeeV
私の現在のコードで間違いを指摘できますか? – JavaCake