如何为Recyclerview的特定项目设置动画?

时间:2019-12-12 09:46:33

标签: android android-recyclerview

这是回收站图片: enter image description here

我想在我单击加号按钮时添加带有动画的新项目 这是代码

select x.*
       ,sum(case when (is_true=1 and lag_val=0) or (lag_val is null) then 1 end) over(partition by customer_id order by id) index_rank
  from (select *
               ,lag(is_true) over(partition by customer_id order by id) lag_val       
          from dbo.t 
        )x

这是setAnimationMethod

select id
       ,customer_id
       ,is_true
       ,dense_rank() over(partition by customer_id order by customer_id,max_grp)
   from(
        select id
               ,customer_id
               ,is_true
               ,max(is_rank) over(partition by customer_id order by id) max_grp
          from (select id,customer_id,is_true
                       ,case when is_true=1 and lag(is_true) over(partition by customer_id order by id)=0 
                              or  lag(is_true) over(partition by customer_id order by id) is null then
                             DENSE_RANK() over(partition by customer_id order by id)
                        end as is_rank
                   from dbo.t
                 )x
      )y

并且lastposition的初始值为-1

1 个答案:

答案 0 :(得分:0)

您在这里通过调用notifyDataSetChanged()来告诉回收者视图您的数据集的全部已更改,应该重绘它们,而实际上您只需要添加的视图在position+1处插入。

仅向回收者视图通知插入的项目,您可以调用notifyItemInserted(position+1)(假设列表项目索引和回收者视图项目位置相同)

您可能还想学习一种实现RecyclerView动画here的巧妙方法,该方法使用内置的android:layoutAnimation属性来定义布局插入动画,即:

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"                                        
    android:layoutAnimation="@anim/layout_animation_fall_down"
    />