咖啡RecyclerView在SwipeRefreshLayout块测试
问题描述:
我有RecyclerView咖啡RecyclerView在SwipeRefreshLayout块测试
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/dashboard_swiperefreshlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/events_dashboard_listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"/>
</android.support.v4.widget.SwipeRefreshLayout>
女巫处于Viewpager片段。 我正在使用volley与自定义IdleResurs进行服务器调用。
我想打开抽屉:
openDrawer(R.id.drawer_layout);
isOpen();
但是,错误的测试挂起:
Could not launch intent Intent within 45 seconds
如果我手动滚动RecycleView或适配器改变显示的页面的测试仍在继续,抽屉被打开。
答
SwipeRefreshLayout的加载指示符可能会显示,因此会阻止UI,因为它是动画。避免布局显示动画的快速解决方法是使用类似下面的代码:
class TestableSwipeRefreshLayout : SwipeRefreshLayout {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
companion object {
var isTestRunning = false
}
override fun setRefreshing(refreshing: Boolean) {
if (!isTestRunning) {
super.setRefreshing(refreshing)
}
}
}