Android - Espresso -滚动到非列表视图项。
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。
更多相关文章
- 导航架构组件 - 具有CollapsingToolbar的详细信息视图
- 仪表测试自定义视图
- 无法将视图添加到相对布局
- ListView的上拉弹簧、下拉弹簧,下拉弹簧时动态带刷新和切换换刷新
- 在android上滚动时,列表视图的位置会发生变化
- 如何在android中的recycler视图中显示第一项的选择?
- springMVC使用html视图配置详解
- 自定义视图无法工作,直到我触摸屏幕
- 做一个没有视图的零食吧?