具有线性布局的图库中的内存错误 - 位图大小超过VM预算

时间:2011-12-01 15:31:55

标签: android gallery

当我滚动超过5个图库元素时,我得到此内存错误(位图大小超过VM)。这是我应用程序的最后一部分,我非常希望能够完成。 我所有的图库图像都是180x180。 我已经在StackOverFlow上阅读了一些“内存错误”主题,但大多数都告诉我将我的图像转换为Bitmaps,我不知道它是如何工作的。如果有人可以为我的问题发布解决方案代码,我将非常感激! 代码在这里:

 public ImageAdapter(Context c) {
        mContext = c;
        TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);                  
        a.recycle();
    }

    public int getCount() {
        return mImageIds.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

        public View getView(final int position, View convertView,ViewGroup parent) {

            if (convertView == null) {
                       LayoutInflater inflater = (LayoutInflater) 
                       mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                       convertView=inflater.inflate(R.layout.l1,null); 

     }
    HighscoreManager hm=new HighscoreManager();
        hm.addScore(timePerWord);         
        ImageView imgView = (ImageView)convertView.findViewById(R.id.imageView1);

        TextView txtView = (TextView)convertView.findViewById(R.id.textView2);                
        if(hm.getHighscoreString()[position]!=0)
        txtView.setText("\t\t    Avg.time: "+hm.getHighscoreString()[position]

);  

            txtView.setTextSize(20);
            imgView.setImageResource(mImageIds[position]);      
            return convertView;

     }

.xml文件L1的位置是:(不是很多,下面是图像和文本视图)

  <?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/l1"
    android:layout_width="240dp"
    android:layout_height="fill_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="240dp"
        android:layout_height="185dp"
        android:layout_x="-1dp"
        android:layout_y="-15dp"
        android:src="@drawable/background" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="38dp"
        android:layout_x="0dp"
        android:layout_y="169dp"
        android:text=""
        android:gravity="center" />

</AbsoluteLayout>

0 个答案:

没有答案