1

我的幻灯片放映活动是我的列表视图行之一,当单击幻灯片放映行时,它必须打开带有动画的幻灯片图像,但在第一张图像出现之前有大约 25 秒的延迟,我尝试在这里更改时间:

int delay = 1000;

但这并不能解决问题,

任何帮助将不胜感激,谢谢

public class SlideShow extends Activity {

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

private int[] IMAGE_IDS = {
        R.drawable.day_one_1, R.drawable.day_one_2,R.drawable.day_one_3, 
        R.drawable.day_one_4, R.drawable.day_one_5,R.drawable.day_one_6,R.drawable.day_one_7,       
        R.drawable.day_one_8, R.drawable.day_one_9,R.drawable.day_one_10
        };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    setContentView(R.layout.slide); 
     if (customTitleSupported) { 
         getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
         TextView tv = (TextView) findViewById(R.id.title_tv1); 
         tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
         tv.setText("slide show");  
         }       
    final Handler mHandler = new Handler();
 // Create runnable for posting
    final Runnable mUpdateResults = new Runnable() {
        public void run() {

            AnimateandSlideShow();              
        }
    };

    int delay = 1000; 

    int period = 5000; 

    Timer timer = new Timer();

    timer.scheduleAtFixedRate(new TimerTask() {

    public void run() {

         mHandler.post(mUpdateResults);
    }

    }, delay, period);                  
}        
private void AnimateandSlideShow() {

    SharedPreferences getPrefs = PreferenceManager
            .getDefaultSharedPreferences(getBaseContext());

    boolean animation_one = getPrefs.getBoolean("animation_one", true);             
    boolean animation_two = getPrefs.getBoolean("animation_two", false);
    boolean animation_three = getPrefs.getBoolean("animation_three", false);    
    boolean animation_four = getPrefs.getBoolean("animation_four", false);
    boolean animation_five = getPrefs.getBoolean("animation_five", false);                          

 if (animation_one == true) {   
    slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);       
    currentimageindex++;
    Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);  
    Animation rotateimage1 = AnimationUtils.loadAnimation(this, R.anim.bounce);            
      //
      AnimationSet s = new AnimationSet(false); 
      s.addAnimation(rotateimage);
      s.addAnimation(rotateimage1);
      slidingimage.startAnimation(s);

}else if(animation_two == true) {
    slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);       
    currentimageindex++;        
    Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.fade_in); 
      slidingimage.startAnimation(rotateimage);   

}else if(animation_three == true) {
    slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);       
    currentimageindex++;        
    Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.move);        
      slidingimage.startAnimation(rotateimage);   

}else if(animation_four == true) {
    slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);       
    currentimageindex++;        
    Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.sequential);        
      slidingimage.startAnimation(rotateimage);   

}else if (animation_five == true) {
    slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);       
    currentimageindex++;
    Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.slide_down);       
      slidingimage.startAnimation(rotateimage);  


}else if(animation_one == false && animation_two == false && animation_three == false
        && animation_four == false && animation_five == false){

    slidingimage = (ImageView)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);       
    currentimageindex++;
    Animation rotateimage = AnimationUtils.loadAnimation(this, R.anim.custom_anim);       
      slidingimage.startAnimation(rotateimage);       
    }
 }   
public boolean onCreateOptionsMenu(android.view.Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);

    getLayoutInflater().setFactory(new Factory() {
    public View onCreateView(String name, Context context,AttributeSet attrs) {

    if (name .equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {
    try {
    LayoutInflater li = LayoutInflater.from(context);
    final View view = li.createView(name, null, attrs);

    new Handler().post(new Runnable() {
    public void run() {

    view .setBackgroundResource(R.drawable.border);

    ((TextView) view).setTextSize(30); 

    ((TextView) view).setTypeface(FontFactory.getBFantezy(getBaseContext()));

    ((TextView) view).setTextColor(Color.RED); 
    }
    });

    return view; 
    }
     catch (InflateException e) {}
      catch (ClassNotFoundException e) {}                                    
    }
    return null; 
    }
    });          
    return super.onCreateOptionsMenu(menu);
                                       }    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {
        case R.id.slide_pref:
              Intent i = new Intent("com.test.demo.SETTING");
              startActivity(i);
        break;
            }
    return false; 
    }
}
4

2 回答 2

0

替换这段代码:

final Handler mHandler = new Handler();
 // Create runnable for posting
 final Runnable mUpdateResults = new Runnable() {
    public void run() {

        AnimateandSlideShow();              
    }
};

int delay = 1000; 

int period = 5000; 

Timer timer = new Timer();

timer.scheduleAtFixedRate(new TimerTask() {

public void run() {

     mHandler.post(mUpdateResults);
}

}, delay, period);                  

}

改写这段代码:

final Handler handler = new Handler();   
 runnable = new Runnable() {
     @Override
    public void run() {
        handler.postDelayed(runnable, 5000);
        AnimateandSlideShow();    
    }
};
handler.postDelayed(runnable, 500);
}

这将导致立即启动图像,

然后您可以根据需要控制出现时间和图像之间的时间,

希望对你有所帮助。

于 2013-09-16T21:15:25.067 回答
0

尝试使用postdelay

private int mSampleDurationTime = 5000; // 1 sec
private boolean continueToNext = true;

Handler mHandler = new Handler();

mHandler.postDelayed(mRunnable, mSampleDurationTime);

mRunnable你的任务在哪里:

private final Runnable mRunnable = new Runnable() {

 //...
public void run() {

   // do something here

   if(continueToNext == true){
    mHandler.postDelayed(mRunnable, mSampleDurationTime);
   }

 }
    ...
};
于 2013-09-14T14:16:06.133 回答