我已经扩展了 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?这应该很容易,但我被卡住了。