我想滚动到显示的当前屏幕的底部,但是
答案 0 :(得分:6)
好的,基于您问题中的少量信息,我可以提出建议:
简单的方法(但不完全正确) - 只需在GridView中向上滑动即可到达底部:
onView(withId(R.id.GridView_Id)).perform(swipeUp());
简单方法:
onData(instanceOf(Object_in_the_ROW.class))
.inAdapterView(withId(R.id.GridView_Id))
.atPosition(2) //position # can very if you have header or not
.check(matches(isDisplayed()))
.perform(click()); //or any other action, or no action
方法我更喜欢:
onData(withROWText("unique_text_in_ROW3"))
.inAdapterView(withId(R.id.GridView_Id))
.check(matches(isDisplayed()))
.perform(click());
其中withRowText()是匹配ROW3中特定文本的自定义匹配器,类似于:
public static Matcher<Object> withRowText(String expectedText) {
Checks.checkNotNull(expectedText);
return withRowText(equalTo(expectedText));
}
public static Matcher<Object> withRowText(final Matcher<String> itemTextMatcher) {
Checks.checkNotNull(itemTextMatcher);
return new BoundedMatcher<Object, ROWObject>(ROWObject.class) {
@Override
public boolean matchesSafely(ROWObject rowObject) {
return itemTextMatcher.matches(rowObject.text);
}
@Override
public void describeTo(Description description) {
description.appendText("with rowObject: ");
itemTextMatcher.describeTo(description);
}
};
}
BTW,“GridView是一个以二维,可滚动网格显示项目的ViewGroup。”