滚动时可以控制滚动视图速度吗?

时间:2017-03-04 12:01:22

标签: android android-layout android-scrollview

我在布局中使用ScrollView,我需要在scrollview.already中控制滚动速度使用manythings.like一个对象动画,定时器,但那些对我没有帮助。那我怎么能控制(或)设置在Android上的scrollview中滚动速度有限。

2 个答案:

答案 0 :(得分:0)

这适用于ViewPager,从未尝试ScrollView

public class FixedSpeedScroller extends OverScroller {

    private int mDuration = 2000;

    public FixedSpeedScroller(Context context) {
        super(context);
    }

    public FixedSpeedScroller(Context context, Interpolator interpolator) {
        super(context, interpolator);
    }


    @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 setFixedDuration(int duration) {
        this.mDuration = duration;
    }
}

如何使用 -

try {
   Field _mScroller = ScrollView.class.getDeclaredField("mScroller");
   _mScroller.setAccessible(true);
   FixedSpeedScroller scroller = new FixedSpeedScroller(mPager.getContext(), new AccelerateDecelerateInterpolator());
   scroller.setFixedDuration(600);
   _mScroller.set(mScrollView, scroller);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
    Log.e("TAG", "Scroller exception"  +e.getLocalizedMessage());
}

试一试。

答案 1 :(得分:0)

如何控制Android ListView滚动速度

您可以使用片段中的代码控制Android ListView的滚动速度:

@Override
public void onStart() {
    super.onStart();
    // scroll speed decreases as friction increases. a value of 2 worked
    // well in an emulator; you need to test it on a real device
    getListView().setFriction(ViewConfiguration.getScrollFriction() * 2);
}

默认情况下,默认ListView滚动速度太快,因此滚动浏览大量项目时,眼睛很难看