对MvxRecyclerView中的选定项目进行动画处理 [英] Animate selected item in MvxRecyclerView

查看:72
本文介绍了对MvxRecyclerView中的选定项目进行动画处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用MvxRecyclerView,并且想为列表中的选定项目设置动画.如何获得对所选项目视图的引用?我应该使用TouchDelegate吗?

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?

推荐答案

您应该能够通过RecyclerAdapter获取视图引用.

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

实施示例:

创建自定义MvxRecyclerAdapter来处理所需的动画.

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);
    }
}

MvxRecyclerView

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

这篇关于对MvxRecyclerView中的选定项目进行动画处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆