Animate selected item in MvxRecyclerView

自古美人都是妖i 提交于 2019-12-24 01:15:19

问题


I am using MvxRecyclerView and I want to animate the selected item in the list. How can I get a reference to the selected item view? Should I use TouchDelegate?


回答1:


You should be able to get the view reference through the RecyclerAdapter.


Implementation Example:

Create a custom MvxRecyclerAdapter to deal with your desired animation.

public class SelectedAnimatorRecyclerAdapter : MvxRecyclerAdapter
{
    public SelectedAnimatorRecyclerAdapter(IMvxAndroidBindingContext bindingContext)
          : base(bindingContext)
    {
    }

    public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
    {
        base.OnBindViewHolder(holder, position);

        holder.ItemView.Click += (s, e) =>
        {
            SetAnimation(holder.ItemView);
        };
    }

    void SetAnimation(View viewToAnimate)
    {
        ScaleAnimation anim = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Dimension.RelativeToSelf, 0.5f, Dimension.RelativeToSelf, 0.5f);
        anim.Duration = 2000;
        viewToAnimate.StartAnimation(anim);
    }
}

Implement adapter in your MvxRecyclerView

var recyclerView = view.FindViewById<MvxRecyclerView>(Resource.Id.my_recycler_view);
recyclerView.Adapter = new SelectedAnimatorRecyclerAdapter((IMvxAndroidBindingContext)BindingContext);



来源:https://stackoverflow.com/questions/38521089/animate-selected-item-in-mvxrecyclerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!