Is there a general approach for scrolling to non-list View items that are not yet visible on the screen?

滚动到屏幕上还不可见的非列表视图项有通用的方法吗?

Without any precautions, Espresso will indicate that "No Views in hierarchy found matching with id .....

在没有任何预防措施的情况下,Espresso将会显示出“在层级中没有找到与id匹配的视图……”

I found this answer ... is this the best approach?

我找到了这个答案……这是最好的方法吗?

onView( withId( R.id.button)).perform( scrollTo(), click());

3 个解决方案

#1


18

According to the scrollTo JavaDoc, to use the code you specified ( onView( withId( R.id.button)).perform( scrollTo(), click()); ), the preconditions are: "must be a descendant of ScrollView" and "must have visibility set to View.VISIBLE". If that is the case, then that will work just fine.

根据scrollTo JavaDoc,使用您指定的代码(onView(带有id (R.id.button)))。执行(scrollTo(),点击()),),前提条件是:“必须是ScrollView的后代”和“必须将可视性设置为View.VISIBLE”。如果是这样,那就没问题了。

If it is in an AdapterView, then you should use onData instead. In some cases, you may have to implement the AdapterViewProtocol, if your AdapterView is not well behaved.

如果是在AdapterView中,那么应该使用onData。在某些情况下,如果AdapterViewProtocol表现不佳,则必须实现该协议。

If it is neither in an AdapterView nor a child of a ScrollView, then you would have to implement a custom ViewAction.

如果它既不在AdapterView中,也不在ScrollView的子视图中,则必须实现自定义ViewAction。

更多相关文章

  1. 导航架构组件 - 具有CollapsingToolbar的详细信息视图
  2. 仪表测试自定义视图
  3. 无法将视图添加到相对布局
  4. ListView的上拉弹簧、下拉弹簧,下拉弹簧时动态带刷新和切换换刷新
  5. 在android上滚动时,列表视图的位置会发生变化
  6. 如何在android中的recycler视图中显示第一项的选择?
  7. springMVC使用html视图配置详解
  8. 自定义视图无法工作,直到我触摸屏幕
  9. 做一个没有视图的零食吧?

随机推荐

  1. Android—自制Android闹钟3步即可!(2020-6
  2. android 获取实时麦克风声音大小
  3. 《Android第一行代码》first reading 十
  4. Android(安卓)7.0 系统解决拍照的问题 ex
  5. Android Broadcast 用法简单讨论
  6. android studio 使用adb 命令传递文件到a
  7. android 一些常用控件属性设置
  8. Android自定义对话框的使用
  9. Android 进阶—— Android 系统安全机制
  10. Android Excel导入