我有一个StaggeredGridLayoutManager,它在2列宽的网格中加载20个卡片,其中包含图像(从缓存、网络或毕加索存储中加载)。
发行:
当前,当您向下滚动列表时,图像会在卡滑到视图中时加载,如下视频所示:
https://www.youtube.com/watch?v=1xMNmMjqEbI
想要的解决方案:
我想要做的是将图像加载到屏幕外,所以有一个无缝的UX,就像这个视频:
https://www.youtube.com/watch?v=4c7ZID7yjII
这些视频来自于一篇用LinearLayoutManager而不是StaggeredGridLayoutManager解决这个问题的博客文章。我似乎想不出这个问题的相应解决办法。我是android开发的新手,我试着阅读文档,但我似乎找不到任何导致解决方案的东西。
代码:
// 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();发布于 2015-05-21 10:14:19
预加载要在缓存中显示的图像,所以在滚动列表时没有加载它们,它们已经在内存中了。
Picasso.with(this).load("url").fetch();另外,删除毕加索的fadeIn动画。
Picasso.with(this).load("url").noFade().into(imageView);发布于 2015-05-21 16:45:35
只是想出了我自己问题的部分解决方案。任何像我这样的新人都会想办法解决这个问题。
RecyclerView方法setItemViewCacheSize(int size)将保持缓存中的条目数量,这样就不会有闪烁类型的视图加载。
不过,我还没有找到前瞻性解决方案来提前加载特定数量的视图。
发布于 2019-08-15 08:45:03
对我来说很管用
Picasso.get()
.load(uploadCurrent.getImageUrl())
.placeholder(R.drawable.logoblack_loading)
.config(Bitmap.Config.RGB_565)
.into(holder.imageView);XML:
<?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>https://stackoverflow.com/questions/30370493
复制相似问题