我已经扩展了RecyclerView以便进行缩放。它按照我的预期工作,但现在我想要以编程方式滚动x个像素。这个功能的用户故事是,如果我点击屏幕的上半部分,它应该滚动x个像素,同样适用于屏幕的下半部分。
这是我所做的:
活动:
@Override
public boolean dispatchTouchEvent(MotionEvent event)
{
// if(mComicViewerFragment != null)
// mComicViewerFragment.consumeEvent(event);
mScaleDetector.onTouchEvent(event);
if(event.getAction() == MotionEvent.ACTION_DOWN)
{
int y = (int) event.getY();
if(y >= mScreenSize.y / 2)
{
mComicViewerFragment.scrollBy((int)(mScreenSize.y * 0.10f));
Log.i(ComicApplication.TAG, "ComicViewerActivity.onTouchEvent : You are tapping the lower part : " + y);
}
else
{
mComicViewerFragment.scrollBy((int)(-mScreenSize.y * 0.10f));
Log.i(ComicApplication.TAG, "ComicViewerActivity.onTouchEvent : You are tapping the upper part : " + y);
}
}
return super.dispatchTouchEvent(event);
}
片段
public void scrollBy(int by)
{
mScalingRecyclerView.smoothScrollBy(0, by);
}
每次我点击时,它不会按照x像素滚动。这是因为我创建了一个扩展自RecyclerView的自定义视图吗?我应该在哪里正确地调用smoothScrollBy?这应该很容易,但我卡住了。
smoothScrollBy
。文档也很清楚:通过给定的像素量沿着任一轴动画滚动。
但是它并没有做到!!! - Neon Warge