遅延が 1 ミリ秒未満のアニメーションを作成しようとしています。
私の調査に基づいて、ScheduledThreadPoolExecutor に関するいくつかの回答が見つかりました。
残念ながら、次のコードを適用しましたが、期待どおりに動作しません..
public class MainActivity extends Activity {
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
private Handler mHandler = new Handler();
public void buttonClicked(View v){
if(v.getId() == R.id.start_animation)
{
//Case1
mHandler.post(animateImage);
//Case2
//startEffect();)
}
}
private Runnable animateImage = new Runnable() {
@Override
public void run() {
runOnUiThread(
new Runnable()
{
public void run()
{
doTheAnimation1();
}
});
}
};
private void doTheAnimation1() {
doFlipImage();
}
private void startEffect()
{
long delay = 1000; //the delay between the termination of one execution and the commencement of the next
exec.scheduleAtFixedRate(animateImage, 0, delay, TimeUnit.MICROSECONDS);
}
}
コードによると、ボタンがクリックされると、mHandler は animateImage を呼び出し、animateImage は doFlipImage を実行してビットマップを作成し、それをキャンバスに割り当て、そのキャンバス上で描画を開始し、このビットマップを使用してイメージビューを無効にします。
mHandler を使用している場合はすべて正常に動作しますが、ScheduledThreadPoolExecutor を使用している場合 (したがって、mHandler.post の代わりに startEffect メソッドを呼び出します)、描画が行われた後にイメージビューが白く表示されます。問題。