我想在图片中制作从0到9的数字幻灯片。当我点击下一个按钮时,显示1的图片并将声音播放为“一个”等等。我想要前一个按钮正常工作...就像我点击上一个按钮然后转到上一个图片并播放与之相关的声音PIC
public class Numbers extends Activity {
int i = 1;
private ImageView iv;
Button next;
Button previous;
MediaPlayer ourSong;
private int currentImage = 0;
public int currentAudio = 0;
int[] images = { R.drawable.p1, R.drawable.p2, R.drawable.p3,
R.drawable.p4, R.drawable.p5, R.drawable.p6, R.drawable.p7,
R.drawable.p8, R.drawable.p9, R.drawable.p10};
int[] audios = { R.raw.a1, R.raw.a2, R.raw.a3, R.raw.a4, R.raw.a5,
R.raw.a6, R.raw.a7, R.raw.a8, R.raw.a9, R.raw.a10};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nextpre);
iv = (ImageView) findViewById(R.id.ivn);
next = (Button) findViewById(R.id.buttonn);
previous = (Button) findViewById(R.id.buttonp);
// Just set one Click listener for the image
next.setOnClickListener(iButtonChangeImageListener);
previous.setOnClickListener(gButtonChangeImageListener);
}
View.OnClickListener iButtonChangeImageListener = new View.OnClickListener() {
public void onClick(View v) {
try {
// Increase Counter to move to next Image
currentImage++;
currentImage = currentImage % images.length;
iv.setImageResource(images[currentImage]);
ourSong = MediaPlayer.create(Numbers.this,
audios[currentAudio+1]);
ourSong.start();
currentAudio++;
} catch (Exception e) {
}
}
};
View.OnClickListener gButtonChangeImageListener = new View.OnClickListener() {
public void onClick(View v) {
try {
// Decrease Counter to move to previous Image
currentImage--;
currentImage = (currentImage + images.length) % images.length;
iv.setImageResource(images[currentImage]);
MediaPlayer.create(Numbers.this, audios[currentAudio]);
ourSong.start();
currentAudio--;
} catch (Exception e) {
}
}
};
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
@Override
protected void onStart() {
super.onStart();
ourSong = MediaPlayer.create(Numbers.this,
audios[0]);
ourSong.start();
}
}
答案 0 :(得分:0)
嗯,如果您正在尝试制作幻灯片,您可能需要查看它们看起来像这样的视图寻呼机:
查看寻呼机是高度可定制的,您可以添加按钮和图像,几乎可以在每个屏幕上保存片段。不知道你的技能水平是什么,但生病告诉你这是什么让这个工作。
这样做是为了切换屏幕你只需要调用setCurrentItem来改变页面(当用户点击next或prev时)
- 编辑 -
显然还有一种叫做ImageSwitcher的东西。 它们看起来像这样:
这实际上更适合您的情况,因为您只需要图像。它比查看寻呼机看起来要容易得多。这描述了如何实现它:http://www.tutorialspoint.com/android/android_imageswitcher.htm