幻灯片动画开始前延迟 [英] Delay before slide show animation start

查看:164
本文介绍了幻灯片动画开始前延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的幻灯片放映活动是我的列表视图行之一,当单击幻灯片排它必须打开幻灯片图像与动画,但周围有25秒直到第一幅图像显示的延迟,
我尝试改变这里的时间:

  INT延迟= 1000;

但修不好,

任何帮助将AP preciated,谢谢

 公共类幻灯片延伸活动{公众诠释currentimageindex = 0;
定时器定时器;
TimerTask的任务;
ImageView的slidingimage;私人诠释[] = 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
        };@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);    布尔customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    的setContentView(R.layout.slide);
     如果(customTitleSupported){
         。getWindow()setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);
         TextView的电视=(的TextView)findViewById(R.id.title_tv1);
         tv.setTypeface(FontFactory.getBFantezy(getBaseContext()));
         tv.setText(幻灯片);
         }
    最后的处理程序mHandler =新的处理程序();
 //创建可运行投寄
    最终的Runnable mUpdateResults =新的Runnable(){
        公共无效的run(){            AnimateandSlideShow();
        }
    };    INT延迟= 1000;    INT周期= 5000;    定时器定时器=新的Timer();    timer.scheduleAtFixedRate(新的TimerTask(){    公共无效的run(){         mHandler.post(mUpdateResults);
    }    },延迟期);
}
私人无效AnimateandSlideShow(){    共享preferences的get preFS = preferenceManager
            .getDefaultShared preferences(getBaseContext());    布尔animation_one = GET prefs.getBoolean(animation_one,真正的);
    布尔animation_two = GET prefs.getBoolean(animation_two,FALSE);
    布尔animation_three = GET prefs.getBoolean(animation_three,FALSE);
    布尔animation_four = GET prefs.getBoolean(animation_four,FALSE);
    布尔animation_five = GET prefs.getBoolean(animation_five,FALSE); 如果(animation_one ==真){
    slidingimage =(ImageView的)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS [currentimageindex%IMAGE_IDS.length]);
    currentimageindex ++;
    动画rotateimage = AnimationUtils.loadAnimation(这一点,R.anim.custom_anim);
    动画rotateimage1 = AnimationUtils.loadAnimation(这一点,R.anim.bounce);
      //
      AnimationSet S =新AnimationSet(假);
      s.addAnimation(rotateimage);
      s.addAnimation(rotateimage1);
      slidingimage.startAnimation(多个);}否则如果(animation_two ==真){
    slidingimage =(ImageView的)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS [currentimageindex%IMAGE_IDS.length]);
    currentimageindex ++;
    动画rotateimage = AnimationUtils.loadAnimation(这一点,R.anim.fade_in);
      slidingimage.startAnimation(rotateimage);}否则如果(animation_three ==真){
    slidingimage =(ImageView的)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS [currentimageindex%IMAGE_IDS.length]);
    currentimageindex ++;
    动画rotateimage = AnimationUtils.loadAnimation(这一点,R.anim.move);
      slidingimage.startAnimation(rotateimage);}否则如果(animation_four ==真){
    slidingimage =(ImageView的)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS [currentimageindex%IMAGE_IDS.length]);
    currentimageindex ++;
    动画rotateimage = AnimationUtils.loadAnimation(这一点,R.anim.sequential);
      slidingimage.startAnimation(rotateimage);}否则如果(animation_five ==真){
    slidingimage =(ImageView的)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS [currentimageindex%IMAGE_IDS.length]);
    currentimageindex ++;
    动画rotateimage = AnimationUtils.loadAnimation(这一点,R.anim.slide_down);
      slidingimage.startAnimation(rotateimage);
}否则如果(animation_one ==假放;&安培; animation_two ==假放;&安培; animation_three ==假
        &功放;&安培; animation_four ==假放;&安培; animation_five == FALSE){    slidingimage =(ImageView的)findViewById(R.id.ImageView_slide);
    slidingimage.setImageResource(IMAGE_IDS [currentimageindex%IMAGE_IDS.length]);
    currentimageindex ++;
    动画rotateimage = AnimationUtils.loadAnimation(这一点,R.anim.custom_anim);
      slidingimage.startAnimation(rotateimage);
    }
 }
公共布尔onCreateOptionsMenu(android.view.Menu菜单){    MenuInflater吹气= getMenuInflater();
    inflater.inflate(R.menu.main,菜单);    getLayoutInflater()。setFactory(新厂(){
    公共查看onCreateView(字符串名称,上下文的背景下,ATTRS的AttributeSet){    如果(名称.equalsIgnoreCase(com.android.internal.view.menu.IconMenuItemView)){
    尝试{
    LayoutInflater李= LayoutInflater.from(背景);
    最后查看视图= li.createView(姓名,空,ATTRS);    新的处理程序()。后(新的Runnable(){
    公共无效的run(){    查看.setBackgroundResource(R.drawable.border);    ((的TextView)视图).setTextSize(30);    ((的TextView)视图).setTypeface(FontFactory.getBFantezy(getBaseContext()));    ((的TextView)视图).setTextColor(Color.RED);
    }
    });    返回视图。
    }
     赶上(InflateException E){}
      捕捉(ClassNotFoundException异常五){}
    }
    返回null;
    }
    });
    返回super.onCreateOptionsMenu(菜单);
                                       }
    @覆盖
    公共布尔onOptionsItemSelected(菜单项项){
        // TODO自动生成方法存根
        开关(item.getItemId()){
        案例R.id.slide_ preF:
              意图I =新意图(com.test.demo.SETTING);
              startActivity(ⅰ);
        打破;
            }
    返回false;
    }
}


解决方案

替换这块code的:

 最后的处理程序mHandler =新的处理程序();
 //创建可运行投寄
 最终的Runnable mUpdateResults =新的Runnable(){
    公共无效的run(){        AnimateandSlideShow();
    }
};INT延迟= 1000;INT周期= 5000;定时器定时器=新的Timer();timer.scheduleAtFixedRate(新的TimerTask(){公共无效的run(){     mHandler.post(mUpdateResults);
}},延迟期);

}

而不是写这个code:

 最后的处理程序处理程序=新的处理程序();
 可运行=新的Runnable(){
     @覆盖
    公共无效的run(){
        handler.postDelayed(可运行,5000);
        AnimateandSlideShow();
    }
};
handler.postDelayed(可运行,500);
}

这会导致启动无延迟的图像,

然后就可以控制出现的时间,并在图像之间,只要你想的时候,

希望可以帮助您。

My slide show Activity is one of my list view rows , when click the slideshow row it must open slide images with animation but there is a delay of around 25 second till first image appear , i try to change the time here:

int delay = 1000;

but that not fix it ,

any help will be appreciated , thanks

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; 
    }
}

解决方案

Replace this piece of code :

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);                  

}

Write instead this code :

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

This will lead to start image without delay ,

then you can control the appearance time and the time in between image as you want,

Hope help you .

这篇关于幻灯片动画开始前延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆