我有一种情况,我正在使用带有图像的水平滚动视图并使用按钮平滑滚动到不同的图像位置。现在它工作正常我只是想知道是否有人知道减慢平滑滚动方法,即有更长的动画时间?目前,捕捉发生得非常快。
也许通过覆盖平滑滚动,我试图搜索这个/示例但没有运气。
那么有什么想法吗?
谢谢,
硅
我有一种情况,我正在使用带有图像的水平滚动视图并使用按钮平滑滚动到不同的图像位置。现在它工作正常我只是想知道是否有人知道减慢平滑滚动方法,即有更长的动画时间?目前,捕捉发生得非常快。
也许通过覆盖平滑滚动,我试图搜索这个/示例但没有运气。
那么有什么想法吗?
谢谢,
硅
怎么样:
ObjectAnimator animator=ObjectAnimator.ofInt(yourHorizontalScrollView, "scrollX",targetXScroll );
animator.setDuration(800);
animator.start();
这是一种方法,对我来说效果很好:
new CountDownTimer(2000, 20) {
public void onTick(long millisUntilFinished) {
hv.scrollTo((int) (2000 - millisUntilFinished), 0);
}
public void onFinish() {
}
}.start();
所以这里水平滚动视图 (hv) 在两秒内从位置 0 移动到 2000 或者如果小于 2000px 则移动到视图的末尾。易于调整...
子类 HorizontalScrollView,使用反射来访问 HorizontalScrollView 中的私有字段mScroller
。当然,如果底层类更改字段名称,这将中断,它默认返回原始滚动实现。
该调用myScroller.startScroll(scrollX, getScrollY(), dx, 0, 500);
更改滚动速度。
private OverScroller myScroller;
private void init()
{
try
{
Class parent = this.getClass();
do
{
parent = parent.getSuperclass();
} while (!parent.getName().equals("android.widget.HorizontalScrollView"));
Log.i("Scroller", "class: " + parent.getName());
Field field = parent.getDeclaredField("mScroller");
field.setAccessible(true);
myScroller = (OverScroller) field.get(this);
} catch (NoSuchFieldException e)
{
e.printStackTrace();
} catch (IllegalArgumentException e)
{
e.printStackTrace();
} catch (IllegalAccessException e)
{
e.printStackTrace();
}
}
public void customSmoothScrollBy(int dx, int dy)
{
if (myScroller == null)
{
smoothScrollBy(dx, dy);
return;
}
if (getChildCount() == 0)
return;
final int width = getWidth() - getPaddingRight() - getPaddingLeft();
final int right = getChildAt(0).getWidth();
final int maxX = Math.max(0, right - width);
final int scrollX = getScrollX();
dx = Math.max(0, Math.min(scrollX + dx, maxX)) - scrollX;
myScroller.startScroll(scrollX, getScrollY(), dx, 0, 500);
invalidate();
}
public void customSmoothScrollTo(int x, int y)
{
customSmoothScrollBy(x - getScrollX(), y - getScrollY());
}
它是一个自动和连续滚动的滚动条。它是通过不断滚动图像列表来显示信用屏幕的。这可能会对您有所帮助或给您一些想法。
改为使用.smoothScrollToPositionFromTop
。例子
listView.smoothScrollToPositionFromTop(scroll.pos(),0,scroll.delay());
哪里scroll
是一个简单的变量,来自一个获取当前屏幕位置的类,.get()
返回新的位置.pos()
和平滑滚动的时间.delay
......等等
看看http://developer.android.com/reference/android/widget/Scroller.html:
滚动的持续时间可以在构造函数中传递,并指定滚动动画应该花费的最长时间