本文介绍了OutOfMemoryError异常的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ImageView的一个问题,我有77图片JPG格式,并有126报价文本,只是简单的应用程序,我想是我要显示所有的报价与背景图片,我使用时,我刷卡左/ viewflipper这样对进入下一报价。我给你我的,我现在用code。希望有人能帮助我..真是浪费我的时间来修复它。我的图片:小320x480

  VF =(ViewFlipper)findViewById(R.id.pages);
            对于(i = 0; I< totalphrase;我++){
                Log.i(ID,+ I);
                VAR = arrayphrase.get(ⅰ);

                //iv.setBackgroundColor(Color.rgb((int)Math.ceil(Math.random()*100),(int)的Math.ceil(的Math.random()* 100),(int)的Math.ceil(数学.random()* 100)));
                的FrameLayout A =新的FrameLayout(本);
                FrameLayout.LayoutParams LP =新FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,FrameLayout.LayoutParams.FILL_PARENT);
                a.setLayoutParams(LP);

                B =新ImageView的(这一点);
                LinearLayout.LayoutParams LP1 =新LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT);
                FrameLayout.LayoutParams LP2 =新FrameLayout.LayoutParams(740,800,Gravity.CENTER);
                //b.setBackgroundColor(Color.rgb((int)Math.ceil(Math.random()*100),(int)的Math.ceil(的Math.random()* 100),(int)的Math.ceil(数学.random()* 100)));

   //我得到的OutOfMemoryError与此,Imgid []  - >我在那里绘制ARA 77picture图片
    b.setBackgroundResource(Imgid [(int)的(的Math.random()* Imgid.length)]);
    //  - 错误 - 内存不足
                b.setLayoutParams(LP1);
                a.addView(B);

                C =新的滚动型(本);
                c.setLayoutParams(LP2);
                //c.setBackgroundColor(Color.CYAN);
                c.setBackgroundColor(Color.argb(65,53,52,52));
                // IDSC = c.getId();
                a.addView(C);

                的LinearLayout D =新的LinearLayout(本);
                d.setLayoutParams(LP1);
                //d.setBackgroundResource(R.drawable.background0);
                c.addView(四);


                TextView的E =新的TextView(本);
                LinearLayout.LayoutParams LP3 =新LinearLayout.LayoutParams(730,800);
                e.setLayoutParams(LP1);
                e.setText(var.phraseKey);

                d.addView(E);


                vf.addView(一);

            }

        }
 

,我想这样的结果是:例子,我想打造的android

这是XML

 < XML版本=1.0编码=UTF-8&GT?;

    <的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android

        机器人:方向=垂直

        机器人:layout_width =FILL_PARENT

        机器人:layout_height =FILL_PARENT

        机器人:ID =@ + ID / FL1
        >


        < ViewFlipper

            机器人:ID =@ + ID /页

            机器人:layout_width =FILL_PARENT

            机器人:layout_height =FILL_PARENT

            机器人:背景=@机器人:彩色/透明

            机器人:layout_gravity =顶
            >
        < / ViewFlipper>


    < /的FrameLayout>
 

尝试把这个code更改图像前:

  imageView.getDrawable()getBitmap()循环();
 

I have a problem with imageview, i have 77 picture jpg and have 126 quote text, just simple app i want is i want show all quote with background picture and i use viewflipper so when i swipe left/right get into next quote. I give you my code that i use now. Hope that anyone can help me.. Really wasting my time to fix it. My picture : 320x480.

                    vf = (ViewFlipper) findViewById(R.id.pages);
            for (i = 0; i<totalphrase;i++) {
                Log.i("ID",""+i);
                var = arrayphrase.get(i);

                //iv.setBackgroundColor(Color.rgb((int)Math.ceil(Math.random()*100), (int)Math.ceil(Math.random()*100), (int)Math.ceil(Math.random()*100)));
                FrameLayout a = new FrameLayout(this);
                FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);
                a.setLayoutParams(lp);

                b = new ImageView(this);
                LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.FILL_PARENT);
                FrameLayout.LayoutParams lp2= new FrameLayout.LayoutParams(740, 800,Gravity.CENTER);
                //b.setBackgroundColor(Color.rgb((int)Math.ceil(Math.random()*100), (int)Math.ceil(Math.random()*100), (int)Math.ceil(Math.random()*100)));

   // i got outofmemoryerror with this, Imgid[] -> my picture in drawable there ara 77picture
    b.setBackgroundResource(Imgid[(int)(Math.random()*Imgid.length)]);
    // -- ERROR --  outofmemory
                b.setLayoutParams(lp1);
                a.addView(b);

                c = new ScrollView(this);
                c.setLayoutParams(lp2);
                //c.setBackgroundColor(Color.CYAN);
                c.setBackgroundColor(Color.argb(65, 53, 52, 52));
                //idsc = c.getId();
                a.addView(c);

                LinearLayout d = new LinearLayout(this);
                d.setLayoutParams(lp1);
                //d.setBackgroundResource(R.drawable.background0);
                c.addView(d);


                TextView e = new TextView(this);
                LinearLayout.LayoutParams lp3 = new LinearLayout.LayoutParams(730, 800);
                e.setLayoutParams(lp1);
                e.setText(var.phraseKey);

                d.addView(e);


                vf.addView(a);

            }

        }

The result that i want like this : example that i want to build in android

and this is xml

        <?xml version="1.0" encoding="utf-8"?>

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:orientation="vertical"

        android:layout_width="fill_parent"

        android:layout_height="fill_parent"

        android:id="@+id/fl1"
        >


        <ViewFlipper

            android:id="@+id/pages"

            android:layout_width="fill_parent"

            android:layout_height="fill_parent"

            android:background="@android:color/transparent"

            android:layout_gravity="top"
            >
        </ViewFlipper>


    </FrameLayout>
解决方案

Try putting this code before changing the image:

imageView.getDrawable().getBitmap().recycle();

这篇关于OutOfMemoryError异常的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 22:15