【问题标题】:Gap between SwipeRefreshLayout and RecyclerViewSwipeRefreshLayout 和 RecyclerView 之间的差距
【发布时间】:2018-01-04 13:22:36
【问题描述】:

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

我正在使用 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)

        }
    }

【问题讨论】:

    标签: android android-recyclerview kotlin swiperefreshlayout anko


    【解决方案1】:

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

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

    【讨论】: