提问者:小点点

如何使用kotlin将layoutmanager设置为RecycleView


我如何设置layoutmanager到RecycleView使用kotlin作为下面java代码:

mRecyclerView.setLayoutManager(mLinearLayoutManager);

共3个答案

匿名用户

以下两条线将方向设置为垂直

mRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL ,false)

mRecyclerView.layoutManager = LinearLayoutManager(this)
mRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL ,false)

设置水平方向

要设置网格布局,

mRecyclerView.layoutManager = GridLayoutManager(this, spanCount)

匿名用户

您可以使用

recyclerView.layoutManager = LinearLayoutManager(context) // default orientation is vertical

// if you want horizontal recyclerview
// recyclerView.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL, false)

匿名用户

您可以尝试使用以下解决方案

val mRecyclerView= v.findViewById<RecyclerView>(R.id.rec) //id RecyclerView    
mRecyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL,false)