我正在为我的主题做作业,但是遇到一个问题,我正在工作的应用程序无法按我想要的方式工作。首先的问题是手电筒会先闪烁,然后在闪烁后动画和声音会同时起作用。我想要的是其中三个可以同时工作。这是代码。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button1);
final MediaPlayer mp = MediaPlayer.create(this, R.raw.wangwang);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
animationblink();
blinkFlash();
mp.start();
}
});
}
private void animationblink(){
ImageView image = (ImageView)findViewById(R.id.imageView1);
Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
image.startAnimation(animation1);
ImageView image1 = (ImageView)findViewById(R.id.imageView2);
Animation animation2 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
image1.startAnimation(animation2);
ImageView image2 = (ImageView)findViewById(R.id.imageView3);
Animation animation3 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink);
image2.startAnimation(animation3);
}
private void blinkFlash()
{
String myString = "010101";
for (int i = 0; i < myString.length(); i++) {
if (myString.charAt(i) == '0') {
cam = Camera.open();
p = cam.getParameters();
p.setFlashMode(Parameters.FLASH_MODE_TORCH);
cam.setParameters(p);
cam.startPreview();
status=true;
}
else {
cam.stopPreview();
cam.release();
status=false;
}
}
}