屏幕

2014-01-22 84 views
0

多的ImageView我想做出一個應用程序上要使用圖像瀏覽器中顯示多個圖像,但在同一時間&第二圖像仍使用按鈕的點擊,我想這是因爲只有一個圖像顯示在屏幕上想要把動畫時圖像出現在屏幕上。在這裏我已經嘗試了刷圖像的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

嘗試下面的代碼來提供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) { 
     } 
    }); 
+0

@GrlsHu如何動畫我添加按鈕控制器刷卡頁面? –

+0

什麼樣的控制器? – GrIsHu

+0

@GrlsHU像一個按鈕和以前按鈕 –