使用Espresso滚动回收器视图

OkD*_*oid 1 android android-espresso android-recyclerview android-espresso-recorder

我有一个异构的回收站视图,我试图将其滚动到位置30处的项目。我的测试通过了,但是我看不到屏幕实际在滚动。

onView(withId(R.id.content_view))
    .perform(RecyclerViewActions.scrollToPosition(30));
Run Code Online (Sandbox Code Playgroud)

这就是我要做的滚动。

den*_*nys 5

用途scrollToHolder()

onView(withId(R.id.recyclerViewId))
    .perform(scrollToHolder(viewHolderMatcher(some_parameter_to_match)));
Run Code Online (Sandbox Code Playgroud)

其中viewHolderMatcher(some_parameter_to_match)返回Matcher<RecyclerView.ViewHolder>,即保持器/项目在RecyclerView的位置。

或仅按位置:

onView(withId(rvLayoutId))
    .perform(actionOnItemAtPosition(256, scrollTo()));
Run Code Online (Sandbox Code Playgroud)

最后一个是从这里


Vic*_*ves 2

您尝试过 ViewActions swipeDown吗?