SwipeRefreshLayout和RecyclerView之间的差距

时间:2018-01-04 13:22:37

标签: android android-recyclerview kotlin swiperefreshlayout anko

如何消除这两者之间的空白? RecyclerView现在从屏幕的一半开始,从第一个元素到工具栏有空白区域。 (只有当我添加足够的项目时,recyclelerview才会从上面开始)。

我正在使用Kotlin和AnkoLayouts。

override fun createView(ui: AnkoContext<ConnectBleActivity>): 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)

        }
    }

1 个答案:

答案 0 :(得分:0)

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

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