问题描述
是否存在一种通用方法来滚动到屏幕上尚不可见的非列表视图项目?
Is there a general approach for scrolling to non-list View items that are not yet visible on the screen?
在没有任何预防措施的情况下,Espresso会指示没有找到层次结构中与ID ....... p匹配的视图".
Without any precautions, Espresso will indicate that "No Views in hierarchy found matching with id .....
我找到了这个答案……这是最好的方法吗?
I found this answer ... is this the best approach?
onView( withId( R.id.button)).perform( scrollTo(), click());
推荐答案
根据 JavaDoc,要使用您指定的代码(onView( withId( R.id.button)).perform( scrollTo(), click());
),先决条件是:必须是ScrollView的后代"和必须将可见性设置为View.VISIBLE
" .如果是这样,那将很好用.
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.
如果在AdapterView
中,则应使用.在某些情况下,如果您的AdapterView
表现不佳,则可能必须实施AdapterViewProtocol
.
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
中也不在ScrollView
的子级中,那么您将必须实现自定义ViewAction
.
If it is neither in an AdapterView
nor a child of a ScrollView
, then you would have to implement a custom ViewAction
.
这篇关于Android-Espresso-滚动到非列表查看项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!