Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to set slide speed? #46

Open
jae1jeong opened this issue Aug 16, 2021 · 1 comment
Open

how to set slide speed? #46

jae1jeong opened this issue Aug 16, 2021 · 1 comment

Comments

@jae1jeong
Copy link

How to set slide speed?
is there any method to set slide speed?

@vidarrrr
Copy link

vidarrrr commented Jun 25, 2022

public class OwnScroller extends Scroller {
    private int durationScrollMs;
    private final int MS = 1000;
    public OScroller(Context context, int secondScrollDuration) {
        super(context);
        this.durationScrollMs = secondScrollDuration * MS;

    }

    @Override
    public void startScroll(int startX, int startY, int dx, int dy, int duration) {
        super.startScroll(startX, startY, dx, dy, this.durationScrollMs);
    }
}
 

Try to create a custom scroller class and override the startScroll function with your own duration.

       LoopingViewPager loopingViewPager = findViewById(R.id.viewpager);
       private final int durationSec = 5;
       try{
            Class<?> viewPager = ViewPager.class;
            Field scroller = viewPager.getDeclaredField("mScroller");
            scroller.setAccessible(true);
            scroller.set(loopingViewPager,new OwnScroller(context,durationSec));

        }catch (Exception e){
            e.printStackTrace();
        }

Try to call with reflection and set your custom scroll class.

src : https://stackoverflow.com/a/42142725

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants