简体   繁体   English

使用 Espresso 滚动 Recycler 视图

[英]Scrolling Recycler view with Espresso

I have a heterogeneous recycler view and I am trying to scroll it to item at position 30. My test is passing but I cannot see the screen actually scrolling.我有一个异构的回收器视图,我试图将它滚动到 position 30 处的项目。我的测试通过了,但我看不到屏幕实际滚动。

onView(withId(R.id.content_view))
    .perform(RecyclerViewActions.scrollToPosition(30));

This is what I am doing to scroll.这就是我正在做的滚动。

Use scrollToHolder() :使用scrollToHolder()

onView(withId(R.id.recyclerViewId))
    .perform(scrollToHolder(viewHolderMatcher(some_parameter_to_match)));

where viewHolderMatcher(some_parameter_to_match) returns Matcher<RecyclerView.ViewHolder> ie the position of the holder/item in the RecyclerView.其中viewHolderMatcher(some_parameter_to_match)返回Matcher<RecyclerView.ViewHolder>即持有者/项目在 RecyclerView 中的位置。

Or only by position:或仅按职位:

onView(withId(rvLayoutId))
    .perform(actionOnItemAtPosition(256, scrollTo()));

last one is from here .最后一个来自这里

您是否尝试过 ViewActions swipeDown

Tell it about the ViewHolder.告诉它有关 ViewHolder 的信息。

onView(withId(R.id.recyclerview)).perform(
        RecyclerViewActions.scrollToPosition<RecyclerView.ViewHolder>(
          YOUR_POSITION
        )
      )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM