• 实现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

  • 相关阅读:
    springCloud和docker笔记(1)——微服务架构概述
    gradle配置远程仓库(以及使用本地maven仓库)
    linux以及git和maven常用命令
    junit使用小结
    aop中获取方法的注解
    mysql使用总结
    mac的终端窗口的工作组的使用
    线性表试题中的操作代码
    echart与Accelerometer综合
    php与MySQL与echart综合使用
  • 原文地址:https://www.cnblogs.com/blogzhangwei/p/4042232.html
Copyright © 2020-2023  润新知