【发布时间】:2018-11-30 14:39:56
【问题描述】:
我觉得我很傻, 我想在我的 RecyclerView 中的 ViewHolder 上使用 MotionLayout 在两种状态之间进行动画处理(当前播放的歌曲被扩展,而最后播放的歌曲被缩小) 不过好像recyclerview太好用了,它只是改变了内容而不改变视图,即当当前播放的歌曲发生变化时,视图已经处于结束转换状态,所以我的转换什么都不做。 同样,我之前展开的项目被反弹到关闭状态,所以我的动画什么都不做。
好吧,我想让我们检查转换的状态并设置进度,但是如果我在前一行设置进度,这会导致转换无法运行。我试过了,增加了一些延迟,但没有真正的改善,
我觉得我可能过度设计了这个,或者我错过了有关如何重置运动布局动画的基本知识。任何帮助将不胜感激。
override fun onBindViewHolder(holder: SongViewHolder, position: Int) {
if (songs.isNotEmpty() && position < songs.size) {
val current = songs[position]
holder.songName?.text = current.song
holder.albumArt?.setImageResource(current.albumArtId)
holder.artistName?.text = current.artist
var ml = holder.motionLayout
if (current.currentPlaying){
//The view is recycled so its already in the end state... so set it to the start state and animate
if (ml?.progress!! > 0f) {
ml?.progress = 0f //<- This resets the animation state
}
ml?.transitionToEnd() <- but at this point the animation does not work if i have manually set the progress the line above
}else{
if (current.previoussong){
//The view that was last expended is not in the end state, so set it then transation to start
if (ml?.progress!! < 1f) {
ml?.progress = 1f
}
ml?.transitionToStart()
}
}
}
}
【问题讨论】:
标签: android recyclerview-layout android-motionlayout