在为imageview提供背景时,如何解决android中的位图大小超出异常

在为imageview提供背景时,如何解决android中的位图大小超出异常,android,android-emulator,Android,Android Emulator,您好,我在这里做一个应用我在使用更多的图像,在arraylist中我有图像我将这些arraylist转换为array,然后我将该字符串数组添加到imageview,但是当活动开始时,我得到的位图大小超过了异常。只是有一段时间我遇到了这个问题,但有时效果很好。有时只有我面对这个问题。。。我尝试了很多方法,但没有结果。我在下面提到我的代码,任何人有想法请建议我 LetterGameActivity .class: public class LetterGameActivity extends

您好,我在这里做一个应用我在使用更多的图像,在arraylist中我有图像我将这些arraylist转换为array,然后我将该字符串数组添加到imageview,但是当活动开始时,我得到的位图大小超过了异常。只是有一段时间我遇到了这个问题,但有时效果很好。有时只有我面对这个问题。。。我尝试了很多方法,但没有结果。我在下面提到我的代码,任何人有想法请建议我

 LetterGameActivity .class:

 public class LetterGameActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

           birdimg1 = (ImageView) findViewById(R.id.birdimg);
        option11 = (TextView)findViewById(R.id.opt1);
        option12 = (TextView)findViewById(R.id.opt2);
        option13 = (TextView)findViewById(R.id.opt3);

                        option11.setText(stringArraynew[0]);
            option12.setText(stringArraynew1[0]);
            option13.setText(stringArraynew2[0]);


             BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            BitmapFactory.decodeResource(getResources(), stringArraynew3[0], options);
            int imageHeight = options.outHeight;
            int imageWidth = options.outWidth;
            String imageType = options.outMimeType;

            birdimg1.setImageBitmap(
                    decodeSampledBitmapFromResource(getResources(), stringArraynew3[0], 100, 100));
}

   public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId,
        int reqWidth, int reqHeight) {

    // First decode with inJustDecodeBounds=true to check dimensions
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(res, resId, options);

    // Calculate inSampleSize
    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

    // Decode bitmap with inSampleSize set
    options.inJustDecodeBounds = false;
    return BitmapFactory.decodeResource(res, resId, options);
}

public static int calculateInSampleSize(
        BitmapFactory.Options options, int reqWidth, int reqHeight) {
// Raw height and width of image
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;

if (height > reqHeight || width > reqWidth) {
    if (width > height) {
        inSampleSize = Math.round((float)height / (float)reqHeight);
    } else {
        inSampleSize = Math.round((float)width / (float)reqWidth);
    }
}
return inSampleSize;
  }
 protected void onPause() {
    super.onPause();
System.gc();
   }
protected void onDestroy()
{
    super.onDestroy();
       System.gc();
    }

    }

是否使用了从option13.setTextstringArraynew2[0]开始的代码;并在oncreate函数中的birdimg1.setImageBitmap处结束??因为这些变量没有使用。是的,在这里我需要为那些文本视图提供onclick函数,而ImageView检查这个粘贴库,我对我正在使用的代码添加注释。