Kotlin和RecyclerView

1、Kotlin下,RecyclerView设置垂直布局,如下图:

Kotlin和RecyclerView_第1张图片

代码:

class ModuleFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, 
            savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_module, container, false)
    }

     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val moduleRecy: RecyclerView = view.findViewById(R.id.function_recy)
        val adapter = FunctionAdapter(list)
        moduleRecy.adapter = adapter
        moduleRecy.layoutManager = LinearLayoutManager(context)
    }

}

 

 

 

你可能感兴趣的:(RecyclerView)