标签:jpg csharp resource insert apt void nta bsp 命名
public virtual void SetItemAnimator(Android.Support.V7.Widget.RecyclerView.ItemAnimator animator)
其中,animator参数指定一个动画,这个动画就是表1-1中列出的动画类型。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="20dp" android:orientation="vertical"> <ImageView android:id="@+id/image" android:layout_width="match_parent" android:layout_height="100dp" android:background="#11000000" android:scaleType="centerCrop"/> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textSize="18sp" /> </LinearLayout>
(6)创建一个适配器文件,命名为DataAdapter。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; using Square.Picasso; using Android.Support.V7.Widget; namespace RecylerViewAnimatorsItemAnimator { public class DataAdapter : RecyclerView.Adapter { Context context; List<string> dataset; //构造方法 public DataAdapter(Context context, List<string> dataset) { this.context = context; this.dataset = dataset; } //子元素的个数 public override int ItemCount { get { return dataset.Count; } } //返回一个自定义的ViewHolder public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) { var v = LayoutInflater.From(context).Inflate(Resource.Layout.layout_list_item, parent, false); return new ViewHolder(v); } //填充onCreateViewHolder()方法返回的ViewHolder中的控件 public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position) { var h = (ViewHolder)holder; Picasso.With(context).Load(Resource.Drawable.image).Into(h.Image); h.Text.Text = dataset[position]; } //删除子元素 public void Remove(int position) { dataset.RemoveAt(position); NotifyItemRemoved(position); } //添加子元素 public void Add(string text, int position) { dataset.Insert(position, text); NotifyItemInserted(position); } private class ViewHolder : RecyclerView.ViewHolder { public ImageView Image { get; private set; } public TextView Text { get; private set; } public ViewHolder(View itemView) : base(itemView) { Image = itemView.FindViewById<ImageView>(Resource.Id.image); Text = itemView.FindViewById<TextView>(Resource.Id.text); } } } }
注意:开发者只有调用NotifyItemRemoved()、NotifyItemInserted()、NotifyItemChanged()和NotifyItemMoved()方法,才可以触发子元素动画。
XamarinAndroid组件教程RecylerView动画组件使用动画(2)
标签:jpg csharp resource insert apt void nta bsp 命名
原文地址:https://www.cnblogs.com/daxueba-ITdaren/p/9044692.html