我正在使用Picasso在我的Android应用程序中显示图像:
/**
* load image.This is within a activity so this context is activity
*/
public void loadImage (){
Picasso picasso = Picasso.with(this);
picasso.setDebugging(true);
picasso.load(quiz.getImageUrl()).into(quizImage);
}
Run Code Online (Sandbox Code Playgroud)
我已启用调试,它始终显示红色和绿色.但从不显示黄色
现在,如果我下次加载相同的图像并且互联网不可用,则不会加载图像.
问题:
我已经实现了一个RecyclerView,主要包含通过Picasso加载的图像.我的问题是,只要我向下或向上滚动视图,占位符图像就会显示约.在它被实际图像替换之前的一秒钟.它滚动非常顺利,但几乎无法使用.每次滚动屏幕时都会发生这种情况.
Picasso显然将图像缓存到磁盘,因为它们的加载速度比初始加载时间快,但它们肯定会立即从缓存中重新加载.我做错了什么?
我的适配器代码:
public class ExploreAdapter extends RecyclerView.Adapter<ExploreAdapter.ExploreViewHolder> {
private List<ExploreItem> exploreItemList;
private Context mContext;
private int deviceWidth = PrefUtils.getDeviceWidth();
public ExploreAdapter(Context context, List<ExploreItem> exploreItemList){
this.mContext = context;
this.exploreItemList = exploreItemList;
}
@Override
public int getItemCount(){
return exploreItemList.size();
}
@Override
public void onBindViewHolder(ExploreViewHolder exploreViewHolder, int i){
ExploreItem item = exploreItemList.get(i);
exploreViewHolder.getvTitle().setText(item.getTitle());
exploreViewHolder.getvUsername().setText(item.getUsername());
exploreViewHolder.getvNumLikes().setText(item.getNbOfLikes());
Picasso.with(mContext).load(item.getMediaLocation().trim())
.resize(deviceWidth, deviceWidth)
.centerCrop()
.placeholder(R.drawable.profile_background)
.into(exploreViewHolder.getvImage());
Picasso.with(mContext).load(item.getUserProfilePicUrl().trim())
.placeholder(R.drawable.profile_picture)
.into(exploreViewHolder.getvProfilePic());
}
@Override
public ExploreViewHolder onCreateViewHolder(ViewGroup viewGroup, int i){
View itemView = LayoutInflater.
from(viewGroup.getContext()).
inflate(R.layout.explore_item, viewGroup, false);
return new …Run Code Online (Sandbox Code Playgroud) java android picasso android-5.0-lollipop android-recyclerview
我一直在搜索SO线程的答案,但无法从之前的讨论中找出我的问题.我有一个listview加载大约50个图像(它曾经是大约100个图像,但根本没有加载任何图像).从api端点获取我的JSON内容(包括图像URL)后,通过适配器,我的代码将其放入listview中.
目前,有50张图片,当我向下滚动Feed时,毕加索将一次加载一张图片.我觉得好像保持滚动固定在列表视图中的一个项目将使该图像加载更快.然而,当我向上滚动时,它会将占位符放回并重新加载图像.有没有办法解决这个问题?
public class MainActivity extends Activity {
private List<Post> myPosts = new ArrayList<Post>();
protected String[] mBlogPostTitles;
public static final String TAG = MainActivity.class.getSimpleName();//prints name of class without package name
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(isNetworkAvailable()) {
GetBlogPostsTask getBlogPostsTask = new GetBlogPostsTask(); // new thread
getBlogPostsTask.execute();// don't call do in background directly
}else{
Toast.makeText(this, "Network is unavailable", Toast.LENGTH_LONG).show();
}
}
public boolean isNetworkAvailable() {
ConnectivityManager manager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
boolean isAvailable = false; …Run Code Online (Sandbox Code Playgroud)