0

私には があり、Listviewその中には 4 種類のビューがあります。それらの1つはViewPager(プレイストアのように)である必要があります。を使用して、3枚の写真PagerAdapterを入れましたViewpagerListviewしかし、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);
    }

}

}

4

0 に答える 0