zoukankan      html  css  js  c++  java
  • 实现Fragment的切换和ViewPager自动循环设置切换时间

    1.FragmentActivity与Fragment之间的用法

    2.实现ViewPager自动轮换,设置移动的时间

     通过反射获取mScrooler这个对象:

        Field mScroller;
                mScroller = ViewPager.class.getDeclaredField("mScroller");
                mScroller.setAccessible(true);
                FixedSpeedScroller scroller = new FixedSpeedScroller(advPager.getContext(), new LinearInterpolator());
                scroller.setmDuration(500);
                mScroller.set(advPager, scroller);

    自定义Scroller类设置移动的时间:


    public
    class FixedSpeedScroller extends Scroller { private int mDuration = 5000; public FixedSpeedScroller(Context context) { super(context); } public FixedSpeedScroller(Context context, Interpolator interpolator) { super(context, interpolator); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) public FixedSpeedScroller(Context context, Interpolator interpolator, boolean flywheel) { super(context, interpolator, flywheel); } @Override public void startScroll(int startX, int startY, int dx, int dy, int duration) { // Ignore received duration, use fixed one instead super.startScroll(startX, startY, dx, dy, mDuration); } @Override public void startScroll(int startX, int startY, int dx, int dy) { // Ignore received duration, use fixed one instead super.startScroll(startX, startY, dx, dy, mDuration); } public void setmDuration(int mDuration) { this.mDuration = mDuration; } }

    附件下载:.zip

  • 相关阅读:
    数组模拟队列实现
    Vue之模板语法
    初识Vue之helloworld
    二、Lambda表达式
    一、函数式编程
    SpringCloudAlibaba之Nacos
    SpringCloudAlibaba之Sentinel
    spring的随笔2
    spring的小想法1
    关于hibernate的一些看法
  • 原文地址:https://www.cnblogs.com/blogzhangwei/p/4042232.html
Copyright © 2011-2022 走看看