一旦图像被按下,它会发生变化并播放声音。 声音播放完毕后,我期望返回到之前的图像(同一ImageView),但这并没有发生。
xml代码:
谢谢。
xml代码:
<ImageView
android:id="@+id/imageView_red_off"
android:src="@drawable/red_orig"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:adjustViewBounds="true"
android:maxHeight="160dp"
android:maxWidth="150dp"
android:layout_gravity="top|left"
android:paddingRight="40dp"
android:paddingLeft="0dp"
android:scaleType="fitCenter"
/>
Java代码:
public boolean onTouch(View view, MotionEvent event) {
.
.
.
if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (colorRed > threshold)) {
whatColor = "Red";
imageRed.setImageResource(R.drawable.red);
}
.
.
.
}
playSound(whatColor);
imageRed.setImageResource(R.drawable.red_orig);
.
.
.
}
在playsound方法中:
if ((color != "None")) {
MediaPlayer mp = MediaPlayer.create(this, animal);
mp.start();
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.release();
};
});
}
谢谢。