开发者

How to set a Delay on imageSwitcher image change (Android)

开发者 https://www.devze.com 2023-01-29 08:11 出处:网络
I\'m working on a menu for my app that is made of a Gallery and sliding it I select a different background image.

I'm working on a menu for my app that is made of a Gallery and sliding it I select a different background image.

 gallery.setOnItemSelectedListener(new Gallery.OnItemSelectedListener() {
   @Override
   public vo开发者_Python百科id onItemSelected(AdapterView<?> arg0, View arg1,
     int arg2, long arg3) {

    imageSwitcher.setImageResource(imm[arg2]);

The idea works decently but the sliding effect is not fluid. My idea is to set a delay, setting:

imageSwitcher.setImageResource(imm[arg2]);

only after a 200ms or so... is something like this possible?

Thank you :) Marco


You can use the Timer and TimerTask class to schedule a operation to happen every 200ms

Something like

Timer scrollTimer = new Timer();
scrollTimer.schedule(
    new TimerTask(){
    @Override
    public void run(){
        runOnUiThread(Call the method to do ur work);
    }
},
0,200);
0

精彩评论

暂无评论...
验证码 换一张
取 消