我有一个Listview
,其中有 4 种不同的视图。其中一个应该是ViewPager
(就像在 Playstore 中一样)。使用 aPagerAdapter
我已将3 张图片Viewpager
放入其中。Listview
但我无法像 PlayStore 那样流畅。
有没有人尝试过这个并且成功了?
我在适配器中的 Getview 如下所示:
public override View GetView(int position, View convertView, ViewGroup parent)
{
int type = position;
if (convertView == null) {
switch (type) {
case 0:
convertView = inflater.Inflate (Resource.Layout.DetailHeader, null);
TextView tv = convertView.FindViewById<TextView> (Resource.Id.Title);
tv.Text = Info.title;
ImageView iv = convertView.FindViewById<ImageView> (Resource.Id.iconImage);
iv.SetImageDrawable (Info.icon);
Button Button = convertView.FindViewById<Button> (Resource.Id.Button);
installButton.Text = "";
installButton.Click += delegate {
confirm ();
};
break;
case 1:
convertView = inflater.Inflate (Resource.Layout.DetailScroller, null);
ImageViewPager adapter = new ImageViewPager (context, appInfo.shots);
ViewPager myPager = convertView.FindViewById<ViewPager> (Resource.Id.imagepager);
myPager.Adapter = adapter;
myPager.SetCurrentItem (0, true);
break;
case 2:
convertView = inflater.Inflate (Resource.Layout.DetailInfo, null);
TextView infoView = convertView.FindViewById<TextView> (Resource.Id.textView);
infoView.Text = "Information";
break;
case 3:
convertView = inflater.Inflate (Resource.Layout.DetailInfo, null);
TextView descView = convertView.FindViewById<TextView> (Resource.Id.textView);
descView.Text = "Description";
break;
}
}
}
ImageViewPager:
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 Android.Support.V4.View;
namespace EnterpriseAppstore
{
class ImageViewPager : PagerAdapter
{
Activity activity;
Android.Graphics.Drawables.BitmapDrawable[] imageArray;
public ImageViewPager(Activity act, Android.Graphics.Drawables.BitmapDrawable[] imgArray) {
imageArray = imgArray;
activity = act;
}
public override int Count {
get {
return imageArray.Length;
}
}
public override Java.Lang.Object InstantiateItem (View p0, int p1)
{
ImageView view = new ImageView(activity);
view.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.FillParent, ViewGroup.LayoutParams.FillParent);
view.SetScaleType(ImageView.ScaleType.FitXy);
view.SetImageDrawable(imageArray[p1]);
((ViewPager) p0).AddView(view, 0);
return view;
}
public override bool IsViewFromObject (View p0, Java.Lang.Object p1)
{
return p0 == ((View) p1);
}
public override void DestroyItem (View p0, int p1, Java.Lang.Object p2)
{
((ViewPager) p0).RemoveView((View) p2);
}
}
}