On Fragment file:
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
recycle_home.layoutManager = LinearLayoutManager( this.context , LinearLayout.VERTICAL ,false )
recycle_home.adapter = adapter_home()
}
问问题
41 次
2 回答
0
override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState)
recycle_home.layoutManager = LinearLayoutManager( this.context)
recycle_home.adapter = adapter_home()
}
或者
override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState)
recycle_home.layoutManager = LinearLayoutManager( this.context,RecyclerView.VERTICAL,false)
recycle_home.adapter = adapter_home()
}
于 2020-05-21T04:13:59.487 回答
0
如果您尝试将布局管理器添加到 RecyclerView,您可以将其添加到 xml 本身
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/emailsRV"
android:layout_width="0dp"
android:layout_height="0dp"
android:adapter="@{adapter}"
android:layoutAnimation="@anim/layout_animation_from_bottom"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toTopOf="@id/addNewACB"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/item_phone" />
然后,如果你想添加方向,你可以将它添加到片段中,或者你甚至可以为相同的创建一个 BindingAdapter
下面是片段/活动的代码
recycle_home.addItemDecoration(DividerItemDecoration(context, LinearLayoutManager.VERTICAL))
于 2020-05-21T04:19:12.670 回答