首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用StaggeredGridLayout预加载毕加索图像

用StaggeredGridLayout预加载毕加索图像
EN

Stack Overflow用户
提问于 2015-05-21 10:01:02
回答 3查看 2.4K关注 0票数 2

我有一个StaggeredGridLayoutManager,它在2列宽的网格中加载20个卡片,其中包含图像(从缓存、网络或毕加索存储中加载)。

发行:

当前,当您向下滚动列表时,图像会在卡滑到视图中时加载,如下视频所示:

https://www.youtube.com/watch?v=1xMNmMjqEbI

想要的解决方案:

我想要做的是将图像加载到屏幕外,所以有一个无缝的UX,就像这个视频:

https://www.youtube.com/watch?v=4c7ZID7yjII

这些视频来自于一篇用LinearLayoutManager而不是StaggeredGridLayoutManager解决这个问题的博客文章。我似乎想不出这个问题的相应解决办法。我是android开发的新手,我试着阅读文档,但我似乎找不到任何导致解决方案的东西。

代码:

代码语言:javascript
复制
    // Setup RecyclerView
    mRecyclerView = (RecyclerView) rootView.findViewById(R.id.gridview_posts);
    mRecyclerView.setHasFixedSize(true);

    // Setup StaggeredGridLayoutManager
    mLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
    mRecyclerView.setLayoutManager(mLayoutManager);

    // Set Adapter
    mPostsAdapter = new PostAdapter(rootView.getContext(), posts);
    mRecyclerView.setAdapter(mPostsAdapter);

    // Start RestClient & get posts
    restClient = new RestClient(getString(R.string.api_location));
    getPosts();
EN

回答 3

Stack Overflow用户

发布于 2015-05-21 10:14:19

预加载要在缓存中显示的图像,所以在滚动列表时没有加载它们,它们已经在内存中了。

代码语言:javascript
复制
 Picasso.with(this).load("url").fetch();

另外,删除毕加索的fadeIn动画。

代码语言:javascript
复制
Picasso.with(this).load("url").noFade().into(imageView);
票数 3
EN

Stack Overflow用户

发布于 2015-05-21 16:45:35

只是想出了我自己问题的部分解决方案。任何像我这样的新人都会想办法解决这个问题。

RecyclerView方法setItemViewCacheSize(int size)将保持缓存中的条目数量,这样就不会有闪烁类型的视图加载。

不过,我还没有找到前瞻性解决方案来提前加载特定数量的视图。

票数 0
EN

Stack Overflow用户

发布于 2019-08-15 08:45:03

对我来说很管用

代码语言:javascript
复制
Picasso.get()
 .load(uploadCurrent.getImageUrl())
 .placeholder(R.drawable.logoblack_loading)
 .config(Bitmap.Config.RGB_565)
 .into(holder.imageView);

XML:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="2dp"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <ImageView
        android:id="@+id/id_imgItem"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:adjustViewBounds="true"/>
    <TextView
        android:id="@+id/textview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/id_imgItem"
        android:paddingTop="4dp"
        android:paddingBottom="4dp"
        android:gravity="center_horizontal"
        android:textSize="18sp"/>

</RelativeLayout>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30370493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档