@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv_images;
final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.imageadapter1, null);
iv_images = (ImageView) convertView.findViewById(R.id.iv_images1);
iv_images.setImageResource(images[position]);
return convertView;
}
java.lang.OutOfMemoryError:无法分配9042060字节 分配8030424可用字节和7MB直到OOM
答案 0 :(得分:1)
您可以使用较小的图像。
您可以尝试此链接 https://developer.android.com/topic/performance/graphics/load-bitmap
答案 1 :(得分:0)
您可以使用诸如Picasso
之类的库@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv_images;
final LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.imageadapter1, null);
iv_images = (ImageView) convertView.findViewById(R.id.iv_images1);
Picasso.get()
.load(images[position])
.resize(YOUR_WIDTH, YOUR_HEIGHT)
.centerCrop()
.into(iv_images)
return convertView;
}
别忘了添加依赖。
等级:
implementation 'com.squareup.picasso:picasso:2.71828'
行家:
<dependency>
<groupId>com.squareup.picasso</groupId>
<artifactId>picasso</artifactId>
<version>2.71828</version>
</dependency>