在位于7 Imageview的XML文件中,例如:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:scaleType="centerInside"
android:src="@drawable/imageview1"
android:clickable="true"
android:layout_gravity="center"
/>
在课堂上:PageFragment扩展Fragment我创建的数组
MediaPlayer[] mediaPlayers= new MediaPlayer[7];
初始化元素
mediaPlayers[0] = MediaPlayer.create(getActivity(), R.raw.england);
mediaPlayers[1]= MediaPlayer.create(getActivity(), R.raw.german);
mediaPlayers[2]= MediaPlayer.create(getActivity(), R.raw.ukraina);
mediaPlayers[3]= MediaPlayer.create(getActivity(), R.raw.russian);
mediaPlayers[4]= MediaPlayer.create(getActivity(), R.raw.belarus);
mediaPlayers[5]= MediaPlayer.create(getActivity(), R.raw.litva);
mediaPlayers[6]= MediaPlayer.create(getActivity(), R.raw.japan);
点击图片查看后我想播放声音
switch (v.getId()) {
case R.id.imageView1:
play mediaPlayers[0]
我希望:如果我点击imagevie2正在播放mediaPlayers [1]声音