How to set the delay when changing imageSwitcher image (Android)

I am working on a menu for my application, which is made from the Gallery and shifts it. I choose a different background image.

 gallery.setOnItemSelectedListener(new Gallery.OnItemSelectedListener() {
   @Override
   public void onItemSelected(AdapterView<?> arg0, View arg1,
     int arg2, long arg3) {

    imageSwitcher.setImageResource(imm[arg2]);

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

imageSwitcher.setImageResource(imm[arg2]);

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

Thanks :) Marco

+3
source share
1 answer

You can use the Timer and TimerTask classes to schedule an operation every 200 ms.

Sort of

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

Source: https://habr.com/ru/post/1779287/


All Articles