我是 xamarin 的初学者,并试图在 android xamarin 上使用这个库(smarteist Android-Image-Slider)。
图书馆来源:
NuGet:
https://www.nuget.org/packages/Karamunting.Android.Smarteist.AutoImageSlider/1.3.2
GitHub:
https://github.com/smarteist/Android-Image-Slider
它正在 android xamarin 上运行,但我不知道如何使用它,只有 android studio 示例。
此类“SliderAdapterExample”现在工作正常
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 Smarteist.AutoImageSlider;
using BumpTech.GlideLib;
namespace PriceChecker
{
public class SliderAdapterExample : SliderViewAdapter
{
private Context context;
private int mCount;
public SliderAdapterExample(Context context)
{
this.context = context;
}
public void setCount(int count)
{
this.mCount = count;
}
public int getCount()
{
//slider view count could be dynamic size
return mCount;
}
public override int Count => 4;
public override void OnBindViewHolder(Java.Lang.Object viewHolder, int position)
{
SliderAdapterVH _viewHolder = (SliderAdapterVH)viewHolder;
_viewHolder.textViewDescription.Text = "This is slider item " + position;
switch (position)
{
case 0:
Glide.With(_viewHolder.itemView)
.Load("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.Into(_viewHolder.imageViewBackground);
break;
case 1:
Glide.With(_viewHolder.itemView)
.Load("https://images.pexels.com/photos/747964/pexels-photo-747964.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260")
.Into(_viewHolder.imageViewBackground);
break;
case 2:
Glide.With(_viewHolder.itemView)
.Load("https://images.pexels.com/photos/929778/pexels-photo-929778.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.Into(_viewHolder.imageViewBackground);
break;
default:
Glide.With(_viewHolder.itemView)
.Load("https://images.pexels.com/photos/218983/pexels-photo-218983.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260")
.Into(_viewHolder.imageViewBackground);
break;
}
}
public override Java.Lang.Object OnCreateViewHolder(ViewGroup parent)
{
View inflate = LayoutInflater.From(parent.Context).Inflate(Resource.Layout.image_slider_layout_item, null);
return new SliderAdapterVH(inflate);
}
class SliderAdapterVH : SliderViewAdapter.ViewHolder
{
public View itemView;
public ImageView imageViewBackground;
public TextView textViewDescription;
public SliderAdapterVH(View itemView) : base(itemView)
{
imageViewBackground = itemView.FindViewById<ImageView>(Resource.Id.iv_auto_image_slider);
textViewDescription = itemView.FindViewById<TextView>(Resource.Id.tv_auto_image_slider);
this.itemView = itemView;
}
}
}
}
但是现在我在图像中的Activity中有很多错误