问题描述
在具有“收藏夹”和水平RecyclerView的图像部分中,是一个适配器 adapterFavoriteProperties ,而该行 带有图表的是主RecyclerView的另一个适配器 adapterChart 。 RecyclerView主视图由行组成,每个行都来自与Concat适配器粘合在一起的不同适配器。
val concatAdapter =
ConcatAdapter(
adapterFavoriteProperties,adapterChart,adapterMostViewedProperties,adapterRecommendedProperties
)
图表的适配器也可以在片段中使用lambda
val chartItemClickLambda: ((Float) -> Unit) = { position ->
println("? DashboardFragment chart CLICK $position")
}
val adapterChart =
ChartContainerAdapter(chartItemClickLambda)
包含标题的部分,请参阅全部,并且recyclerView是
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="propertyListModel"
type="com.smarttoolfactory.dashboard.model.PropertyItemListModel" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
visibilityBasedOn="@{!propertyListModel.items.isEmpty()}"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="8dp"
android:text="@{propertyListModel.title}"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/tvSeeAll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
visibilityBasedOn="@{propertyListModel.seeAll}"
android:text="See all"
android:textColor="#FB8C00"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@id/tvTitle"
app:layout_constraintEnd_toEndOf="parent"
tools:text="See all" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
app:items="@{propertyListModel.items}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
它是适配器
class horizontallistWithTitleAdapter(
private val onItemClick: ((PropertyItem) -> Unit)? = null
) :
listadapter<PropertyItemListModel,HorizontalItemViewHolder>(
DefaultItemDiffCallback()
) {
override fun onCreateViewHolder(parent: ViewGroup,viewType: Int): HorizontalItemViewHolder {
return HorizontalItemViewHolder(
DataBindingUtil.inflate(
LayoutInflater.from(parent.context),R.layout.layout_list_with_title,parent,false
),onItemClick
)
}
override fun onBindViewHolder(holder: HorizontalItemViewHolder,position: Int) {
holder.bindTo(currentList[position])
}
}
和ViewHolder
class HorizontalItemViewHolder(
private val binding: LayoutListWithTitleBinding,private val onItemClick: ((PropertyItem) -> Unit)? = null
) :
RecyclerView.ViewHolder(binding.root) {
fun bindTo(item: PropertyItemListModel) {
binding.setvariable(BR.propertyListModel,item)
binding.recyclerView.apply {
// Set Layout manager
this.layoutManager =
Scaledlinearlayoutmanager(this.context,linearlayoutmanager.HORIZONTAL,false)
// Set RecyclerViewAdapter
val itemlistadapter = Propertylistadapter(R.layout.item_property_favorite,onItemClick)
this.adapter = itemlistadapter
}
binding.executePendingBindings()
}
}
在这里我应该引用RecyclerView或让ViewHolder称为recyclerView的smoothScrollToPosition(position)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)