【发布时间】:2022-01-14 19:01:20
【问题描述】:
不确定是否有人发生过这种情况,但是当我为 RecycleView 中的某个项目(childView)更改某些内容时,同样适用于下方/上方的项目 12 位置。有人对此有任何见解吗?
override fun onInterceptTouchEvent(view: RecyclerView, e: MotionEvent): Boolean {
val childView = view.findChildViewUnder(e.x, e.y)
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
val letterOfDay = childView.findViewById<TextView>(R.id.letterOfDay)
val dayOfMonth = childView.findViewById<TextView>(R.id.dayOfMonth)
val dayOfMonthActive = childView.findViewById<ImageView>(R.id.button)
dayOfMonthActive.visibility = View.VISIBLE
letterOfDay.setTextColor(Color.parseColor("#ffffff"))
dayOfMonth.setTextColor(Color.parseColor("#001419"))
mListener.onItemClick(childView, view.getChildAdapterPosition(childView))
return true
}
return false
}
因此,此代码为相隔 12 个位置的 2 个不同项目设置文本颜色。它被调用了一次,我认为它与 RecyclerView 有关。
编辑:当我打电话时
recyclerView.findChildViewUnder(1f,1f)
或
view.findChildViewUnder(e.x, e.y)
它并没有精确到单个子视图,而是针对我的情况下的 2,但我不确定它为什么会这样做。
【问题讨论】:
标签: android android-recyclerview