我想创建一个想要使用imageviewer显示多个图像的应用程序,但一次只能在屏幕上显示一个图像&第二个图像来点击按钮,我想要这个因为想要在图像进入屏幕时放动画。在这里,我尝试了轻扫图像的viewpager。是否有可能在使用viewpager时我们可以在屏幕上显示每个图像时放置动画。
这是我的完整活动代码
public class Numbers extends Activity {
MediaPlayer mp;
MediaPlayer BG;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_numbers);
ViewPagerAdapter adapter = new ViewPagerAdapter(this, imageArra);
ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
myPager.setOnPageChangeListener(player);
myPager.setAdapter(adapter);
myPager.setCurrentItem(0);
BG = MediaPlayer.create(this, R.raw.jingle);
BG.setLooping(true);
BG.setVolume(100, 100);
BG.start();
mp = MediaPlayer.create(Numbers.this, mAudio[0]);
mp.start();
}
@Override
protected void onPause() {
super.onPause();
BG.pause();
}
@Override
protected void onResume() {
super.onResume();
BG.start();
}
private int[] mAudio = new int[]{R.raw.one,
R.raw.two,
R.raw.three,
R.raw.four,
R.raw.five,
R.raw.six,
R.raw.seven,
R.raw.eight,
R.raw.nine,
R.raw.ten};
private int imageArra[] = {R.drawable.no1,
R.drawable.no2,
R.drawable.no3,
R.drawable.no4,
R.drawable.no5,
R.drawable.no6,
R.drawable.no7,
R.drawable.no8,
R.drawable.no9,
R.drawable.no10};
public OnPageChangeListener player = new OnPageChangeListener()
{
@Override
public void onPageSelected(int arg1)
{
mp = MediaPlayer.create(Numbers.this, mAudio[arg1]);
mp.start();
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2)
{
}
@Override
public void onPageScrollStateChanged(int arg0)
{
}
};
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.numbers, menu);
return true;
}
}
请为我推荐教程或解决方案..
答案 0 :(得分:0)
尝试使用以下代码在ViewPager
Timer timer = new Timer();
public void pageSwitcher(int seconds) {
timer = new Timer(); // At this line a new Thread will be created
timer.schedule(new RemindTask(), 6000, seconds * 1000); // delay
// in milliseconds
}
// this is an inner class...
class RemindTask extends TimerTask {
@Override
public void run() {
// As the TimerTask run on a seprate thread from UI thread we have
// to call runOnUiThread to do work on UI thread.
runOnUiThread(new Runnable() {
public void run() {
myPager.setCurrentItem(myPager.getCurrentItem() + 1);
}
});
}
}
myPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int arg0) {
Log.e("pageselectrd", "selected:" + String.valueOf(arg0));
timer.cancel();
pageSwitcher(5);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});