我想要显示ViewPager约50页,每页包含不同的图像.使用Picasso,前20-25页完美无缺.但是,那时我得到了一个OutOfMemoryError,并没有任何图像加载:
Throwing OutOfMemoryError "Failed to allocate a 7477932 byte allocation with 1932496 free bytes"
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码PagerAdapter:
@Override
public Object instantiateItem(final ViewGroup container, final int position) {
View view = getView();
Picasso picasso = getImageLoader(mContext);
picasso.load(getUrl(position)).fit().into((ImageView) view.findViewById(R.id.imageview));
container.addView(view);
return view;
}
@Override
public void destroyItem(final ViewGroup container, final int position, final Object object) {
container.removeView((View) object);
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能避免这种情况?
nha*_*man 16
我发现了这个问题.
一些要点指出:
skipMemoryCache()builder.executor(Executors.newSingleThreadExecutor());Picasso:不要Picasso.Builder每次都使用创建新实例.我设法解决了最后一个问题.
Mar*_*cus 10
这个问题在Google点击率上排名很高,所以我正在为这个问题添加我的解决方案.
添加.fit()解决了我的问题.我正在使用以下代码成功加载图像.
picasso.load(PartyUtil.getPartyIconResourceFromFullPartyName(parties.get(position)))
.fit()
.into(holder.icon);
Run Code Online (Sandbox Code Playgroud)
删除.fit()导致我的应用程序抛出OutOfMemoryException.
| 归档时间: |
|
| 查看次数: |
6274 次 |
| 最近记录: |