我正在使用MvxRecyclerView,我想为列表中的选定项目设置动画。如何获取所选项目视图的引用?我应该使用TouchDelegate吗?
答案 0 :(得分:9)
您应该可以通过RecyclerAdapter
获取视图参考。
实施示例:
创建自定义MvxRecyclerAdapter
以处理您想要的动画。
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);