我正在创建一个通用添加或减少位图的应用。 问题是,当我添加超过6个位图时,它会崩溃。
Bitmap oneIcon,twoIcon,threeIcon,fourIcon,fiveIcon,sixIcon,sevenIcon,eightIcon,nineIcon,tenIcon,elevenIcon,twelveIcon,thirteenIcon,fourteenIcon,fifteenIcon;
oneIcon = BitmapFactory.decodeResource(getResources(), R.drawable.one);
twoIcon = BitmapFactory.decodeResource(getResources(), R.drawable.two);
threeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.three);
fourIcon = BitmapFactory.decodeResource(getResources(), R.drawable.four);
fiveIcon = BitmapFactory.decodeResource(getResources(), R.drawable.five);
sixIcon = BitmapFactory.decodeResource(getResources(), R.drawable.six);
sevenIcon = BitmapFactory.decodeResource(getResources(), R.drawable.seven);
eightIcon = BitmapFactory.decodeResource(getResources(), R.drawable.eight);
nineIcon = BitmapFactory.decodeResource(getResources(), R.drawable.nine);
tenIcon = BitmapFactory.decodeResource(getResources(), R.drawable.ten);
elevenIcon = BitmapFactory.decodeResource(getResources(), R.drawable.eleven);
twelveIcon = BitmapFactory.decodeResource(getResources(), R.drawable.twelve);
thirteenIcon = BitmapFactory.decodeResource(getResources(), R.drawable.thirteen);
fourteenIcon = BitmapFactory.decodeResource(getResources(), R.drawable.fourteen);
fifteenIcon = BitmapFactory.decodeResource(getResources(), R.drawable.fifteen);
答案 0 :(得分:0)
如果你真的需要像这样使用Bitmap
,你应该只在必要时创建它,然后正确地回收它。
另外,请确保您的图片不是太大,您可以使用Android Asset Studio调整图片大小。