在我的活动中,我正在播放动画。当我第一次开始活动时,所有动画都在播放给定的持续时间。但是当我重复每一个动画更多的时间时它会加速。这是我的活动......而在我的代码中我没有提供所有对象和变量声明来减少代码......
公共类练习扩展活动{ /** 在第一次创建活动时调用。 * /
@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 :(得分:0)
我不确定,但是如果您使用CountDownTimers
并且多次按下它,则会启动它们两次或更多次。也许你的动画也是同样的问题。我看到swim_Animation.start();
例如..在重新激活它之前尝试swim_Animation.stop();
。我希望我没有误解你的解释..