2012-02-15 3 views
1

私の活動では、私はアニメーションを再生しています。初めてアクティビティを開始するとき、すべてのアニメーションが所定の期間再生されています。しかし、それは私が各アニメーションをより多くの時間繰り返すときにスピードアップしています。これは私の活動です....そして私のコードでは、コードを減らすためにオブジェクトと変数の宣言をすべて提供していません...アニメーションが初回実行後にスピードアップするのはなぜですか?

public class Exercise extends Activity { /**アクティビティが初めて作成されたときに呼び出されます。 */

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.exercise); 

    exercise_Layout=(RelativeLayout)findViewById(R.id.exerciselayout); 

    exercise_Layout.setBackgroundResource(R.drawable.exercise_bg); 

    if(getIntent().getStringExtra("TIPS").equals("Fun")) 
    { 
    count=0; 
    System.out.println("This is Fun"); 
    } 
    else if(getIntent().getStringExtra("TIPS").equals("Tips")) 
    { 
    count=1; 

    } 
gym.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
          exercise_Layout.setBackgroundResource(R.drawable.exercise_bg); 
      gym_View.setBackgroundResource(R.anim.gymanim); 
      gym_Animation=(AnimationDrawable)gym_View.getBackground(); 
      gym_Animation.start(); 
      //playing sounds 
      mp.reset(); 
      mp=MediaPlayer.create(getApplicationContext(),R.raw.gym); 
      try { 
       mp.prepare(); 
      } catch (IllegalStateException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      mp.start(); 
      mp.setLooping(true);  

     } 
    }); 

    run.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 
          exercise_Layout.setBackgroundResource(R.drawable.exercise_bg); 
      run_View.setBackgroundResource(R.anim.runanim); 
      run_Animation=(AnimationDrawable)run_View.getBackground(); 
      run_Animation.start(); 
      //playing sounds 
      mp.reset(); 
      mp=MediaPlayer.create(getApplicationContext(),R.raw.thread_music); 
      try { 
       mp.prepare(); 
      } catch (IllegalStateException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      mp.start(); 
      mp.setLooping(true);  

     } 
    }); 

    jogg.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      jogg_View.setBackgroundResource(R.anim.jogroadanim); 
      jogg_Animation=(AnimationDrawable)jogg_View.getBackground(); 
      jogg_Animation.start(); 
      //playing sounds 
      mp.reset(); 
      mp=MediaPlayer.create(getApplicationContext(),R.raw.jogging); 
      try { 
       mp.prepare(); 
      } catch (IllegalStateException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      mp.start(); 
      mp.setLooping(true);  

     } 
    }); 

    swim.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      exercise_Layout.setBackgroundResource(R.drawable.swimingpool); 
      swim_View.setVisibility(View.VISIBLE); 

      swim_View.setBackgroundResource(R.anim.swimanim); 
      swim_Animation=(AnimationDrawable)swim_View.getBackground(); 
      swim_Animation.start(); 
      //playing sounds 
      mp.reset(); 
      mp=MediaPlayer.create(getApplicationContext(),R.raw.swimming); 
      try { 
       mp.prepare(); 
      } catch (IllegalStateException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      mp.start(); 
      mp.setLooping(true);  

     } 
    }); 
} 

答えて

0

- 私わからないが、あなたはCountDownTimersを使用していて、その上に複数回押した場合は、2回以上、それらを開始します。あなたのアニメーションと同じ問題かもしれません。例えば、swim_Animation.start();が表示されます。再アクティブ化する前にswim_Animation.stop();を試してください。私はあなたの説明を誤解していないことを願っています..

関連する問題