【发布时间】:2021-03-31 18:35:45
【问题描述】:
如何制作Stagered RecyclerView?让列随机站立,我是初学者和这么多java教程stageredrecyclerview,关于Kotlin教程如何制作随机stageredRecyclerView不幸的是我还没有找到,请有人简单介绍一下。谢谢提前
这是我的代码(我已经用 xml 编写的列和分阶段管理器)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="#F4F4F4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/RecyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layoutManager="androidx.recyclerview.widget.StaggeredGridLayoutManager"
app:spanCount="2"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/item_recycler"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
class AgroMarktFragment: Fragment(), IntFaceClickRecycler {
var binding : AgromarktLayoutBinding? = null
private val vm by viewModel<AgroMarkViewModel>()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = AgromarktLayoutBinding.inflate(layoutInflater)
return binding?.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
hereWeGo()
}
private fun hereWeGo() {
val adapter = AgroAdapter(this)
binding?.RecyclerView?.adapter = adapter
vm.data.observe(viewLifecycleOwner, Observer {
adapter.update(it)
})
}
override fun gotoTheDetails(data: Dataclass) {
val dest = HomeFragmentDirections.actionHomeFragmentToDetailsFragment(data)
findNavController().navigate(dest)
}
}
【问题讨论】:
标签: kotlin android-recyclerview