0

我需要帮助 pagerView。当我在一百页后使用 pagerview 时,应用程序给我错误“内存不足”。我需要一种方法来破坏视图,因为它让我一直都在记忆中(从头到尾)。在视图中记住我制作的 4 个带有图像(不会更改)和两个按钮的框。

这是我的适配器:

namespace ProvaViewPager
{
    public class FragmentAdapter : FragmentStatePagerAdapter
    {
        int mCount;
        private FragmentManager mFragmentManager;

        public FragmentAdapter (FragmentManager fm) : base (fm)
        {
            mCount = 200;
            mFragmentManager = fm;
        }

        public override Fragment GetItem (int position)
        {
            return new SwiftView (position);
        }

        public override int Count {
            get {
                return mCount;  
            }   
        }

使用方法distroy?但如何?

调试消息:

跳过了 55 帧!应用程序可能在其主线程上做了太多工作。将目标 GC 堆从 49.446MB 钳制到 48.000MB 将目标 GC 堆从 49.847MB 钳制到 48.000MB 将目标 GC 堆从 49.860MB 钳制到 48.000MB 将目标 GC 堆从 49.859MB 钳制到 48.000MB 强制收集软引用以分配 712 字节钳制目标 GC 堆从 49.859MB 到 48.000MB 在 712 字节分配上内存不足。将目标 GC 堆从 49.874MB 钳制到 48.000MB 将目标 GC 堆从 49.874MB 钳制到 48.000MB 强制收集软引用以进行 964 字节分配 将目标 GC 堆从 49.874MB 钳制到 48.000MB 在 964 字节分配上内存不足。单声道.Debugging.Evaluation.EvaluatorException:Java.Lang.OutOfMemoryError:

在 Mono.Debugging.Soft.MethodCall.get_ReturnValue()

在 Mono.Debugging.Soft.SoftEvaluationContext.RuntimeInvoke(MethodMirror 方法,对象目标,Value[] 值)

在 Mono.Debugging.Soft.SoftDebuggerAdaptor.CallToString(EvaluationContext ctx, Object obj)

在 Mono.Debugging.Evaluation.ObjectValueAdaptor.TargetObjectToObject(EvaluationContext ctx, Object obj)

在 Mono.Debugging.Soft.SoftDebuggerAdaptor.TargetObjectToObject(EvaluationContext gctx, Object obj)

在 Mono.Debugging.Evaluation.ExpressionEvaluator.TargetObjectToExpression(EvaluationContext ctx, Object obj)

在 Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValueImpl(EvaluationContext ctx,IObjectValueSource 源,ObjectPath 路径,Object obj,ObjectValueFlags 标志)

在 Mono.Debugging.Evaluation.ObjectValueAdaptor.CreateObjectValue(EvaluationContext ctx, IObjectValueSource source, ObjectPath path, Object obj, ObjectValueFlags flags) 将目标 GC 堆从 49.874MB 固定到 48.000MB 将目标 GC 堆从 49.874MB 固定到 48.000MB 强制收集 SoftReferences对于 964 字节分配,将目标 GC 堆从 49.874MB 限制到 48.000MB 在 964 字节分配中内存不足。将目标 GC 堆从 49.874MB 钳制到 48.000MB

抱歉英语不好

4

1 回答 1

0

然后创建一个 ViewPager 包含一个框,由一个图像组成并写......每个页面由 4 个框组成。这是我的创建框代码:

 namespace ProvaViewPager.Widget.CatalogoBox

{

    public class CatalogoBox : RelativeLayout

    {

        private LayoutInflater _mInflater;

        private LinearLayout _mBox;



        private void Initialize ()

        {

        }



        public CatalogoBox (IntPtr doNotUse, JniHandleOwnership transfer)

            : base(doNotUse, transfer)

        {

        }



        public CatalogoBox (Context context, IAttributeSet attrs)

            : base(context, attrs)

        {

            InternalCtor (context, attrs);

        }



        public CatalogoBox (Context context, IAttributeSet attrs, int defStyle)

            : base(context, attrs, defStyle)

        {

            InternalCtor (context, attrs);

        }



        ~CatalogoBox ()

        {

            Dispose (false);

        }





        private void InternalCtor (Context context, IAttributeSet attrs)

        {

            _mInflater = (LayoutInflater)context.GetSystemService (Context.LayoutInflaterService);

            _mBox = (LinearLayout)_mInflater.Inflate (Resource.Layout.CatalogoBox, null);

            AddView (_mBox);

        }

    }

}

在这里(SwiftView 类:Fragment)我们记得:

public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)

    {

        TextView TxtCDPAR;

        TextView TxtDEPAR;

        TextView TxtPrezzo;

        TextView TxtPz;



        ImageView ImageDisp;

        ImageView ImgFreccia;

        ImageView ImgIncrementa;

        ImageView ImgDecrementa;

        ImageView ImageItem;

        EditText Quantita;

        ImageView ImageProduct;

        LinearLayout BoxAddProdotto;

        View v = inflater.Inflate (Resource.Layout.PageViewXml, container, false);

        if (v != null) {

            #region BOX1

            var BoxProdotto1 = v.FindViewById<ProvaViewPager.Widget.CatalogoBox.CatalogoBox> (Resource.Id.CatalogoBox1);

            TxtCDPAR = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_TxtCodiceProdotto);

            TxtDEPAR = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_DescrProdotto);

            ImageView ImagetItem1 = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct) as ImageView;

            TxtPz = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_NumeroPezzi);

            TxtPrezzo = BoxProdotto1.FindViewById<TextView> (Resource.Id.CAT_TxtPrezzo);

            BoxAddProdotto = BoxProdotto1.FindViewById<LinearLayout> (Resource.Id.BoxAddProdotto);

            ImageDisp = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImgDisp);

            ImgFreccia = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImgFreccia);

            ImgIncrementa = BoxProdotto1.FindViewById<ImageView> (Resource.Id.imageIncrementa);

            ImgDecrementa = BoxProdotto1.FindViewById<ImageView> (Resource.Id.imageDecrementa);

            Quantita = BoxProdotto1.FindViewById<EditText> (Resource.Id.editNumerico);

            ImageProduct = BoxProdotto1.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct);

            TxtPz.Visibility = ViewStates.Invisible;



            ImagetItem1.SetImageResource (Resource.Drawable.imagespiaggia);



            #endregion



            #region BOX2

            var BoxProdotto2 = v.FindViewById<ProvaViewPager.Widget.CatalogoBox.CatalogoBox> (Resource.Id.CatalogoBox2);

            TxtCDPAR = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_TxtCodiceProdotto);

            TxtDEPAR = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_DescrProdotto);

            ImageItem = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct) as ImageView;

            TxtPz = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_NumeroPezzi);

            TxtPrezzo = BoxProdotto2.FindViewById<TextView> (Resource.Id.CAT_TxtPrezzo);

            BoxAddProdotto = BoxProdotto2.FindViewById<LinearLayout> (Resource.Id.BoxAddProdotto);

            ImageDisp = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImgDisp);

            ImgFreccia = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImgFreccia);

            ImgIncrementa = BoxProdotto2.FindViewById<ImageView> (Resource.Id.imageIncrementa);

            ImgDecrementa = BoxProdotto2.FindViewById<ImageView> (Resource.Id.imageDecrementa);

            Quantita = BoxProdotto2.FindViewById<EditText> (Resource.Id.editNumerico);

            ImageProduct = BoxProdotto2.FindViewById<ImageView> (Resource.Id.CAT_ImageProduct);

            TxtPz.Visibility = ViewStates.Invisible;



            ImageItem.SetImageResource (Resource.Drawable.feliximage);



            #endregion

这是适配器:

namespace ProvaViewPager

{

public class FragmentAdapter : FragmentStatePagerAdapter

{

    int mCount;

    private FragmentManager mFragmentManager;



    public FragmentAdapter (FragmentManager fm) : base (fm)

    {

        mCount = 200;

        mFragmentManager = fm;

    }



    public override Fragment GetItem (int position)

    {

        return new SwiftView (position);

    }



    public override int Count {

        get {

            return mCount;  

        }   

    }



    public override Java.Lang.Object InstantiateItem (ViewGroup container, int position)

    {
        return base.InstantiateItem (container, position);

    }



    public override void DestroyItem (ViewGroup collection, int position, Java.Lang.Object view)

    {

        base.DestroyItem(collection,position,view);



    }

}

}

于 2013-06-11T10:46:36.697 回答