【发布时间】:2020-02-13 18:19:13
【问题描述】:
我一直在尝试为scenario 制作动画。基本上我想从一些开始 ImageViews 垂直排列并散布在屏幕上,在执行特定操作(按下按钮等)后,它们应该靠近。值得一提的是,ImageView 的数量可能会因情况而异(并不总是像图片中那样 3 个),因此更可取的是通用解决方案。
我的第一种方法是在Recyclerview 中列出图像,然后使用自定义ItemDecoration 传播图像,如下所示:
class CustomItemDecorator(private val spaceHeight: Int) : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
with(outRect) {
if (parent.getChildAdapterPosition(view) == 0) {
top = spaceHeight
}
bottom = spaceHeight
}
}
}
通过删除 ItemDecorator (myRecyclerView.removeItemDecoration(my_decorator))
我能够使图像更接近。
尽管这适用于任意数量的图像以改善用户体验,但我想动画这个过渡。我尝试将一些更复杂的动画应用到我的 RecyclerView,但到目前为止没有任何效果。
如果有任何建议,我会很高兴 :-)
【问题讨论】:
标签: android android-recyclerview android-animation objectanimator item-decoration