SwipeRefreshLayout和RecyclerView之间的差距

如何消除这两者之间的空隙? RecyclerView现在开始靠近屏幕的一半,从第一个元素到工具栏都有空白区域。 (只有当我添加足够的物品recyclerview开始顶部)。

我正在使用Kotlin和AnkoLayouts。

override fun createView(ui: AnkoContext): View = with(ui) { return relativeLayout { lparams(width = matchParent, height = matchParent) addItemButton = floatingActionButton { imageResource = android.R.drawable.ic_input_add }.lparams { margin = dip(10) alignParentBottom() alignParentEnd() alignParentRight() gravity = Gravity.BOTTOM or Gravity.END } swipeRefreshLayout = swipeRefreshLayout { rv = recyclerView { layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true) adapter = listAdapter lparams(width = matchParent, height = wrapContent) } }.lparams(width = matchParent, height = wrapContent) } } 

通过在SwipeRefreshLayout中放置另一个布局解决了这个问题。

  swipeRefreshLayout = swipeRefreshLayout { linearLayout { rv = recyclerView { layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, true) adapter = listAdapter lparams(width = matchParent, height = wrapContent) } } }