2012-03-10 65 views
1

我想以不同的时间间隔显示几张图像,但是我可以以相同的时间间隔显示图片,因为它可能会以不同的间隔显示图片吗?例如,第一个图像显示5秒,第二个图像7秒,第三个图像4秒等...任何想法和/或示例?Android:如何以不同的时间间隔显示图像?

这是我的活动,我展示,但在相等的间隔图片:

public class WCourse extends Activity implements OnClickListener, OnTouchListener, OnCompletionListener, OnBufferingUpdateListener{ 

//mp3 player 
private ImageButton buttonPlayPause; 
private SeekBar seekBarProgress; 
public EditText editTextSongURL; 


public static TextView TextViewTopTitle; 

//Slider 
public int currentimageindex=0; 
Timer timer; 
TimerTask task; 
ImageView slidingimage; 

//images ids 
private int[] IMAGE_IDS = { 
     R.drawable.c5_d1, R.drawable.c5_d2, R.drawable.c5_d3, R.drawable.c5_d4, R.drawable.c5_d5, 
     R.drawable.c5_d6, R.drawable.c5_d7, R.drawable.c5_d8, R.drawable.c5_d9, R.drawable.c5_d10, 
     R.drawable.c5_d11, R.drawable.c5_d12, R.drawable.c5_d13, R.drawable.c5_d14, R.drawable.c5_d15, 
     R.drawable.c5_d16, R.drawable.c5_d17, R.drawable.c5_d18, R.drawable.c5_d19, R.drawable.c5_d20, 
     R.drawable.c5_d21, R.drawable.c5_d22, R.drawable.c5_d23, R.drawable.c5_d24, R.drawable.c5_d25, 
     R.drawable.c5_d26, R.drawable.c5_d27, R.drawable.c5_d28, R.drawable.c5_d29, R.drawable.c5_d30, 
     R.drawable.c5_d31, R.drawable.c5_d32, R.drawable.c5_d33, R.drawable.c5_d34, R.drawable.c5_d35, 
     R.drawable.c5_d36, R.drawable.c5_d37, R.drawable.c5_d38, R.drawable.c5_d39, R.drawable.c5_d40, 
     R.drawable.c5_d41, R.drawable.c5_d42, R.drawable.c5_d43, R.drawable.c5_d44, R.drawable.c5_d45, 
     R.drawable.c5_d46 
    }; 

//player  
private MediaPlayer mediaPlayer; 
private int mediaFileLengthInMilliseconds; // this value contains the song duration in milliseconds. Look at getDuration() method in MediaPlayer class 

//slider handler 
private final Handler handler = new Handler(); 

/** Called when the activity is first created. 
* @param <MyCount>*/ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.watch_course); 

    //intent 
    TextViewTopTitle = (TextView) findViewById(R.id.TextViewTopTitle); 
    Bundle bundle = getIntent().getExtras(); 
    TextViewTopTitle.setText(bundle.getString("RESULT2")+" "); 
    getText(bundle.getString("RESULT2")); 

    final Handler mHandler = new Handler();  
    initView(); 

    final Runnable mUpdateResults = new Runnable() { 
     public void run() { 

      AnimateandSlideShow(); 

     } 
    }; 
    final int delay = 5000; // delay for xx sec.  

    final long period = 11000;//repet every xx seconds  
    Timer timer = new Timer(); 
    timer.scheduleAtFixedRate(new TimerTask() { 

    public void run() { 

     mHandler.post(mUpdateResults); 
    } 

}, delay, period);}  
// Helper method to start the animation on the splash screen 
    private void AnimateandSlideShow() { 
slidingimage = (ImageView)findViewById(R.id.ImageView3_Left); 
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]); 
currentimageindex++; 
slidingimage.getAnimation();} 

真的会感谢你的帮助。

+0

为什么不使用随机生成的数字而不是当前的具体值?例如Brandt的 – 2012-03-10 03:21:46

+0

? – JLouis 2012-03-10 03:43:11

+0

重新设置了答案 - 我不是真的在做其他工作的业务,但我完全在思考过程中工作 - 所以如果我离开基地说,否则我认为你错过了森林的树木 – 2012-03-10 03:45:03

回答

1
 public void run(){ 
     try{          
      Thread.sleep(4000);     
     }        
     catch(Exception ex){ 

      Log.e("Welcome Exception :",ex.toString()); 
     }      
     mHandler.sendEmptyMessage(0);  
    } 
0

为什么不使用随机生成的数字而不是当前的特定值?

我的意思是:

final int delay = 5000; // delay for xx sec.  

final long period = 11000;//repet every xx seconds 

?似乎是一个oversite或可能即时读取这个错误

相关问题