我有以下水平滚动视图,我以编程方式将项目添加到其中:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="vm"
type="com.sample.android.tmdb.ui.detail.MovieDetailViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:visibleGone="@{vm.isTrailersVisible}">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/trailers"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<HorizontalScrollView
android:id="@+id/trailer_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:items="@{vm.trailers}" />
</HorizontalScrollView>
</LinearLayout>
</layout>
在这里我添加了一些项目:
@JvmStatic
@BindingAdapter("items")
fun addItems(linearLayout: LinearLayout, trailers: List<Video>) {
linearLayout.removeAllViews()
val context = linearLayout.context
for (trailer in trailers) {
val thumbContainer = context.layoutInflater.inflate(R.layout.video, linearLayout, false)
val thumbView = thumbContainer.findViewById<ImageView>(R.id.video_thumb)
thumbView.apply {
setOnClickListener {
val playVideoIntent = Intent(Intent.ACTION_VIEW, Uri.parse(Video.getUrl(trailer)))
context.startActivity(playVideoIntent)
}
}
linearLayout.addView(thumbContainer)
}
}
现在我想添加一个
Espresso
HorizontalScrollView
然后点击第三项。直到现在我写了以下测试:
@Test
fun shouldBeAbleToDisplayTrailer() {
onView(withId(R.id.list)).perform(RecyclerViewActions
.actionOnItemAtPosition<MovieViewHolder>(8, click()))
onView(withId(R.id.trailer_scroll_view)).perform(nestedScrollTo()).check(matches(isDisplayed()))
// intended(Matcher<Intent> matcher) asserts the given matcher matches one and only one
// intent sent by the application.
//intended(allOf(hasAction(Intent.ACTION_VIEW)))
}
但我不知道怎么滚动
. 你能帮忙吗?