我将所有无限长的滚动视图切换到回收站视图。然而,这使得一些事情变得更加艰难。
这是我的回收者视图的助手类:
namespace BookOfLife.Screens.Helpers
{
class RecyclerViewHolder : RecyclerView.ViewHolder
{
public ImageView imageView { get; set; }
public TextView txtDescription { get; set; }
public RecyclerViewHolder(View itemView):base(itemView)
{
txtDescription = itemView.FindViewById<TextView>(Resource.Id.RecView_Profile_TaskName);
imageView = itemView.FindViewById<ImageView>(Resource.Id.imageView1);
}
}
class RecyclerViewAdapter : RecyclerView.Adapter
{
private List<DataForProfile> lstData = new List<DataForProfile>();
public RecyclerViewAdapter(List<DataForProfile> lstData)
{
this.lstData = lstData;
}
public override int ItemCount
{
get
{
return lstData.Count;
}
}
public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
{
RecyclerViewHolder viewHolder = holder as RecyclerViewHolder;
viewHolder.txtDescription.Text = (lstData[position].description);
viewHolder.imageView.SetImageBitmap((lstData[position].img));
}
public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
{
LayoutInflater inflater = LayoutInflater.From(parent.Context);
View itemView = inflater.Inflate(Resource.Layout.RecView_Profile, parent, false);
return new RecyclerViewHolder(itemView);
}
}
public class DataForProfile
{
public int imageId { get; set; }
public Bitmap img { get; set; }
public string description { get; set; }
}
问题:
我还需要在回收站视图的顶部显示一个仅显示ONCE的项目。像某种标题。我一直无法弄清楚如何做到这一点。
这是我初始化RC视图的代码:
private void initRecView()
{
RecyclerView recycler;
RecyclerViewAdapter adapter;
RecyclerView.LayoutManager layoutManager;
startNumberOfTask = 0;
List<KumulosHelper.Objects.Picture> pictures =
KumulosHelper.Pictures.getNewestXPhotosFromUserInRange
(strUsername, "4", startNumberOfTask.ToString(), "0"); // 4 Bilder werden momentan nur reingeladen!
foreach (var picture in pictures)
{
startNumberOfTask++;
var metrics = Resources.DisplayMetrics;
lstData.Add(new DataForProfile()
{
imageId = startNumberOfTask,
img = (Bitmap.CreateScaledBitmap
(KumulosGeneral.DecodePhotoFromBase64(picture.photo),
metrics.WidthPixels, metrics.WidthPixels, true)),
description = picture.taskId.ToString()
});
}
recycler = FindViewById<RecyclerView>(Resource.Id.recview);
recycler.HasFixedSize = true;
layoutManager = new LinearLayoutManager(this);
recycler.SetLayoutManager(layoutManager);
adapter = new RecyclerViewAdapter(lstData);
recycler.SetAdapter(adapter);
}
在我的AXML Layoutfile中,我只有一个不断重复的图像的布局。
谢谢!