RecyclerView blinking after notifyDatasetChanged()
I have a RecyclerView which loads some data from API, includes an image url and some data, and I use networkImageView to lazy load image.
@Override
public void onResponse(List<Item> response) {
mItems.clear();
for (Item item : response) {
mItems.add(item);
}
mAdapter.notifyDataSetChanged();
mSwipeRefreshLayout.setRefreshing(false);
}
Here is implementation for Adapter:
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
if (isHeader(position)) {
return;
}
// - get element from your dataset at this position
// - replace the contents of the view with that element
MyViewHolder holder = (MyViewHolder) viewHolder;
final Item item = mItems.get(position - 1); // Subtract 1 for header
holder.title.setText(item.getTitle());
holder.image.setImageUrl(item.getImg_url(), VolleyClient.getInstance(mCtx).getImageLoader());
holder.image.setErrorImageResId(android.R.drawable.ic_dialog_alert);
holder.origin.setText(item.getOrigin());
}
Problem is when we have refresh in the recyclerView, it is blincking for a very short while in the beginning which looks strange.
I just used GridView/ListView instead and it worked as I expected. There were no blincking.
configuration for RecycleView in onViewCreated of my Fragment
:
mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
mGridLayoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return mAdapter.isHeader(position) ? mGridLayoutManager.getSpanCount() : 1;
}
});
mRecyclerView.setAdapter(mAdapter);
Anyone faced with such a problem? what could be the reason?
android android-fragments android-recyclerview
add a comment |
I have a RecyclerView which loads some data from API, includes an image url and some data, and I use networkImageView to lazy load image.
@Override
public void onResponse(List<Item> response) {
mItems.clear();
for (Item item : response) {
mItems.add(item);
}
mAdapter.notifyDataSetChanged();
mSwipeRefreshLayout.setRefreshing(false);
}
Here is implementation for Adapter:
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
if (isHeader(position)) {
return;
}
// - get element from your dataset at this position
// - replace the contents of the view with that element
MyViewHolder holder = (MyViewHolder) viewHolder;
final Item item = mItems.get(position - 1); // Subtract 1 for header
holder.title.setText(item.getTitle());
holder.image.setImageUrl(item.getImg_url(), VolleyClient.getInstance(mCtx).getImageLoader());
holder.image.setErrorImageResId(android.R.drawable.ic_dialog_alert);
holder.origin.setText(item.getOrigin());
}
Problem is when we have refresh in the recyclerView, it is blincking for a very short while in the beginning which looks strange.
I just used GridView/ListView instead and it worked as I expected. There were no blincking.
configuration for RecycleView in onViewCreated of my Fragment
:
mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
mGridLayoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return mAdapter.isHeader(position) ? mGridLayoutManager.getSpanCount() : 1;
}
});
mRecyclerView.setAdapter(mAdapter);
Anyone faced with such a problem? what could be the reason?
android android-fragments android-recyclerview
Possible duplicate of Disable onChange animations on ItemAnimator for RecyclerView
– Apfelsaft23
Nov 24 '18 at 15:06
add a comment |
I have a RecyclerView which loads some data from API, includes an image url and some data, and I use networkImageView to lazy load image.
@Override
public void onResponse(List<Item> response) {
mItems.clear();
for (Item item : response) {
mItems.add(item);
}
mAdapter.notifyDataSetChanged();
mSwipeRefreshLayout.setRefreshing(false);
}
Here is implementation for Adapter:
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
if (isHeader(position)) {
return;
}
// - get element from your dataset at this position
// - replace the contents of the view with that element
MyViewHolder holder = (MyViewHolder) viewHolder;
final Item item = mItems.get(position - 1); // Subtract 1 for header
holder.title.setText(item.getTitle());
holder.image.setImageUrl(item.getImg_url(), VolleyClient.getInstance(mCtx).getImageLoader());
holder.image.setErrorImageResId(android.R.drawable.ic_dialog_alert);
holder.origin.setText(item.getOrigin());
}
Problem is when we have refresh in the recyclerView, it is blincking for a very short while in the beginning which looks strange.
I just used GridView/ListView instead and it worked as I expected. There were no blincking.
configuration for RecycleView in onViewCreated of my Fragment
:
mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
mGridLayoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return mAdapter.isHeader(position) ? mGridLayoutManager.getSpanCount() : 1;
}
});
mRecyclerView.setAdapter(mAdapter);
Anyone faced with such a problem? what could be the reason?
android android-fragments android-recyclerview
I have a RecyclerView which loads some data from API, includes an image url and some data, and I use networkImageView to lazy load image.
@Override
public void onResponse(List<Item> response) {
mItems.clear();
for (Item item : response) {
mItems.add(item);
}
mAdapter.notifyDataSetChanged();
mSwipeRefreshLayout.setRefreshing(false);
}
Here is implementation for Adapter:
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
if (isHeader(position)) {
return;
}
// - get element from your dataset at this position
// - replace the contents of the view with that element
MyViewHolder holder = (MyViewHolder) viewHolder;
final Item item = mItems.get(position - 1); // Subtract 1 for header
holder.title.setText(item.getTitle());
holder.image.setImageUrl(item.getImg_url(), VolleyClient.getInstance(mCtx).getImageLoader());
holder.image.setErrorImageResId(android.R.drawable.ic_dialog_alert);
holder.origin.setText(item.getOrigin());
}
Problem is when we have refresh in the recyclerView, it is blincking for a very short while in the beginning which looks strange.
I just used GridView/ListView instead and it worked as I expected. There were no blincking.
configuration for RecycleView in onViewCreated of my Fragment
:
mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
// use this setting to improve performance if you know that changes
// in content do not change the layout size of the RecyclerView
mRecyclerView.setHasFixedSize(true);
mGridLayoutManager = (GridLayoutManager) mRecyclerView.getLayoutManager();
mGridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
return mAdapter.isHeader(position) ? mGridLayoutManager.getSpanCount() : 1;
}
});
mRecyclerView.setAdapter(mAdapter);
Anyone faced with such a problem? what could be the reason?
android android-fragments android-recyclerview
android android-fragments android-recyclerview
edited Mar 30 '15 at 8:35
Ali
asked Mar 29 '15 at 15:35
AliAli
4,6331650114
4,6331650114
Possible duplicate of Disable onChange animations on ItemAnimator for RecyclerView
– Apfelsaft23
Nov 24 '18 at 15:06
add a comment |
Possible duplicate of Disable onChange animations on ItemAnimator for RecyclerView
– Apfelsaft23
Nov 24 '18 at 15:06
Possible duplicate of Disable onChange animations on ItemAnimator for RecyclerView
– Apfelsaft23
Nov 24 '18 at 15:06
Possible duplicate of Disable onChange animations on ItemAnimator for RecyclerView
– Apfelsaft23
Nov 24 '18 at 15:06
add a comment |
12 Answers
12
active
oldest
votes
Try using stable IDs in your RecyclerView.Adapter
setHasStableIds(true)
and override getItemId(int position)
.
Without stable IDs, after notifyDataSetChanged()
, ViewHolders usually assigned to not to same positions. That was the reason of blinking in my case.
You can find a good explanation here.
3
works perfectly. freaking awesome
– Ajay Shrestha
Aug 30 '16 at 20:42
3
This is the most correct answer
– Daniel López Lacalle
Sep 27 '16 at 12:43
prefect solution
– Naveen Kumar M
Oct 28 '16 at 8:38
this should be marked as the right answer
– Jignesh Shah
Dec 21 '16 at 12:18
2
Any idea on how should we generate the ID?
– Mauker
Jul 25 '17 at 16:34
|
show 7 more comments
According to this issue page ....it is the default recycleview item change animation... You can turn it off.. try this
recyclerView.getItemAnimator().setSupportsChangeAnimations(false);
Change in latest version
Quoted from Android developer blog:
Note that this new API is not backward compatible. If you previously
implemented an ItemAnimator, you can instead extend
SimpleItemAnimator, which provides the old API by wrapping the new
API. You’ll also notice that some methods have been entirely removed
from ItemAnimator. For example, if you were calling
recyclerView.getItemAnimator().setSupportsChangeAnimations(false),
this code won’t compile anymore. You can replace it with:
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
3
@sabeer still same issue. It is not resolving the issue.
– iDroid Explorer
Mar 22 '16 at 3:51
3
@delive let me know if you found any solution to this
– iDroid Explorer
Mar 22 '16 at 3:51
I'm use picasso, its something, not appear blink.
– delive
Mar 22 '16 at 8:05
great its working fine.
– RAHULRSANNIDHI
Aug 17 '16 at 9:21
3
Kotlin: (recyclerView.itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
– Pedro Paulo Amorim
Dec 7 '16 at 15:20
|
show 1 more comment
This simply worked:
recyclerView.getItemAnimator().setChangeDuration(0);
1
Worked like a charm! thanks
– Alireza
Jun 29 '16 at 11:36
it's a good alternative tocode
ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); }code
– ziniestro
Sep 14 '16 at 2:40
stops all the animations ADD and REMOVE
– MBH
Aug 4 '17 at 23:23
add a comment |
I have the same issue loading image from some urls and then imageView blinks.
Solved by using
notifyItemRangeInserted()
instead of
notifyDataSetChanged()
which avoids to reload those unchanged old datas.
add a comment |
try this to disable the default animation
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
this the new way to disable the animation since android support 23
this old way will work for older version of the support library
recyclerView.getItemAnimator().setSupportsChangeAnimations(false)
add a comment |
Assuming mItems
is the collection that backs your Adapter
, why are you removing everything and re-adding? You are basically telling it that everything has changed, so RecyclerView rebinds all views than I assume the Image library does not handle it properly where it still resets the View even though it is the same image url. Maybe they had some baked in solution for AdapterView so that it works fine in GridView.
Instead of calling notifyDataSetChanged
which will cause re-binding all views, call granular notify events (notify added/removed/moved/updated) so that RecyclerView will rebind only necessary views and nothing will flicker.
3
Or maybe it is just a "bug" in RecyclerView? Obviously if it worked fine for last 6 years with AbsListView and now it doesn't with RecyclerView, means something is not OK with RecyclerView, right? :) Quick look into it shows that when you refresh data in ListView and GridView they keep track of view+position, so when you refresh you will get exactly the same viewholder. While RecyclerView shuffles view holders, which leads in flickering.
– vovkab
May 20 '15 at 17:09
Working on ListView does not mean it is correct for RecyclerView. These components have different architectures.
– yigit
May 20 '15 at 19:27
1
Agree, but sometimes it is really hard to know what items is changed, for example if you use cursors or you just refresh you whole data. So recyclerview should handle this case correctly too.
– vovkab
May 20 '15 at 20:58
add a comment |
Hey @Ali it might be late replay. I also faced this issue and solved with below solution, it may help you please check.
LruBitmapCache.java class is created to get image cache size
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements
ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
public LruBitmapCache() {
this(getDefaultLruCacheSize());
}
public LruBitmapCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
}
VolleyClient.java singleton class [extends Application] added below code
in VolleyClient singleton class constructor add below snippet to initialize the ImageLoader
private VolleyClient(Context context)
{
mCtx = context;
mRequestQueue = getRequestQueue();
mImageLoader = new ImageLoader(mRequestQueue,getLruBitmapCache());
}
I created getLruBitmapCache() method to return LruBitmapCache
public LruBitmapCache getLruBitmapCache() {
if (mLruBitmapCache == null)
mLruBitmapCache = new LruBitmapCache();
return this.mLruBitmapCache;
}
Hope its going to help you.
Thanks for your answer. That's what I have exactly done in my VollyClient.java. Take a look at :VolleyClient.java
– Ali
Jun 20 '15 at 12:25
Just check once with using LruCache<String, Bitmap> class, I think its going to solve your problem. Take a look at LruCache
– Android learner
Jun 20 '15 at 14:55
Did you check once the code that I shared with you in comment? what do you have in your class that I missed there?
– Ali
Jun 20 '15 at 15:04
You are missing extending LruCache<String, Bitmap> class and overriding sizeOf() method like how I done, remaining all are seems okay to me.
– Android learner
Jun 20 '15 at 15:11
Ok, I give it a try very soon, but could you explain me what have you done there which did the magic for you and solve the problem? sourcecode For me it sounds like your overriden sizeOf method should be in the source code.
– Ali
Jun 20 '15 at 16:48
|
show 4 more comments
Recyclerview uses DefaultItemAnimator as it's default animator.
As you can see from the code below, they change the alpha of the view holder upon item change:
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
...
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
...
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
....
ViewCompat.setAlpha(newHolder.itemView, 0);
}
...
return true;
}
I wanted to retain the rest of the animations but remove the "flicker" so I cloned DefaultItemAnimator and removed the 3 alpha lines above.
To use the new animator just call setItemAnimator() on your RecyclerView:
mRecyclerView.setItemAnimator(new MyItemAnimator());
add a comment |
I had similar issue and this worked for me
You can call this method to set size for image cache
private int getCacheSize(Context context) {
final DisplayMetrics displayMetrics = context.getResources().
getDisplayMetrics();
final int screenWidth = displayMetrics.widthPixels;
final int screenHeight = displayMetrics.heightPixels;
// 4 bytes per pixel
final int screenBytes = screenWidth * screenHeight * 4;
return screenBytes * 3;
}
add a comment |
for my application, I had some data changing but I didn't want the entire view to blink.
I solved it by only fading the oldview down 0.5 alpha and starting the newview alpha at 0.5. This created a softer fading transition without making the view disappear completely.
Unfortunately because of private implementations, I couldn't subclass the DefaultItemAnimator in order to make this change so I had to clone the code and make the following changes
in animateChange:
ViewCompat.setAlpha(newHolder.itemView, 0); //change 0 to 0.5f
in animateChangeImpl:
oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() { //change 0 to 0.5f
add a comment |
for me recyclerView.setHasFixedSize(true);
worked
add a comment |
Using appropriate recyclerview methods to update views will solve this issue
First, make changes in the list
mList.add(item);
or mList.addAll(itemList);
or mList.remove(index);
Then notify using
notifyItemInserted(addedItemIndex);
or
notifyItemRemoved(removedItemIndex);
or
notifyItemRangeChanged(fromIndex, newUpdatedItemCount);
Hope this will help!!
Absolutely not. If you are making several updates by seconds (BLE scanning in my case) it doesn't work at all. I spent one day to update to this shit RecyclerAdapter... Better to keep ArrayAdapter. It's a shame that's not using MVC pattern, but at least it's almost usable.
– Gojir4
Jun 4 '18 at 15:01
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29331075%2frecyclerview-blinking-after-notifydatasetchanged%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
12 Answers
12
active
oldest
votes
12 Answers
12
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try using stable IDs in your RecyclerView.Adapter
setHasStableIds(true)
and override getItemId(int position)
.
Without stable IDs, after notifyDataSetChanged()
, ViewHolders usually assigned to not to same positions. That was the reason of blinking in my case.
You can find a good explanation here.
3
works perfectly. freaking awesome
– Ajay Shrestha
Aug 30 '16 at 20:42
3
This is the most correct answer
– Daniel López Lacalle
Sep 27 '16 at 12:43
prefect solution
– Naveen Kumar M
Oct 28 '16 at 8:38
this should be marked as the right answer
– Jignesh Shah
Dec 21 '16 at 12:18
2
Any idea on how should we generate the ID?
– Mauker
Jul 25 '17 at 16:34
|
show 7 more comments
Try using stable IDs in your RecyclerView.Adapter
setHasStableIds(true)
and override getItemId(int position)
.
Without stable IDs, after notifyDataSetChanged()
, ViewHolders usually assigned to not to same positions. That was the reason of blinking in my case.
You can find a good explanation here.
3
works perfectly. freaking awesome
– Ajay Shrestha
Aug 30 '16 at 20:42
3
This is the most correct answer
– Daniel López Lacalle
Sep 27 '16 at 12:43
prefect solution
– Naveen Kumar M
Oct 28 '16 at 8:38
this should be marked as the right answer
– Jignesh Shah
Dec 21 '16 at 12:18
2
Any idea on how should we generate the ID?
– Mauker
Jul 25 '17 at 16:34
|
show 7 more comments
Try using stable IDs in your RecyclerView.Adapter
setHasStableIds(true)
and override getItemId(int position)
.
Without stable IDs, after notifyDataSetChanged()
, ViewHolders usually assigned to not to same positions. That was the reason of blinking in my case.
You can find a good explanation here.
Try using stable IDs in your RecyclerView.Adapter
setHasStableIds(true)
and override getItemId(int position)
.
Without stable IDs, after notifyDataSetChanged()
, ViewHolders usually assigned to not to same positions. That was the reason of blinking in my case.
You can find a good explanation here.
edited Jul 5 '18 at 21:19
Spipau
1,8711931
1,8711931
answered Sep 9 '15 at 19:53
Anatoly VdovichevAnatoly Vdovichev
94964
94964
3
works perfectly. freaking awesome
– Ajay Shrestha
Aug 30 '16 at 20:42
3
This is the most correct answer
– Daniel López Lacalle
Sep 27 '16 at 12:43
prefect solution
– Naveen Kumar M
Oct 28 '16 at 8:38
this should be marked as the right answer
– Jignesh Shah
Dec 21 '16 at 12:18
2
Any idea on how should we generate the ID?
– Mauker
Jul 25 '17 at 16:34
|
show 7 more comments
3
works perfectly. freaking awesome
– Ajay Shrestha
Aug 30 '16 at 20:42
3
This is the most correct answer
– Daniel López Lacalle
Sep 27 '16 at 12:43
prefect solution
– Naveen Kumar M
Oct 28 '16 at 8:38
this should be marked as the right answer
– Jignesh Shah
Dec 21 '16 at 12:18
2
Any idea on how should we generate the ID?
– Mauker
Jul 25 '17 at 16:34
3
3
works perfectly. freaking awesome
– Ajay Shrestha
Aug 30 '16 at 20:42
works perfectly. freaking awesome
– Ajay Shrestha
Aug 30 '16 at 20:42
3
3
This is the most correct answer
– Daniel López Lacalle
Sep 27 '16 at 12:43
This is the most correct answer
– Daniel López Lacalle
Sep 27 '16 at 12:43
prefect solution
– Naveen Kumar M
Oct 28 '16 at 8:38
prefect solution
– Naveen Kumar M
Oct 28 '16 at 8:38
this should be marked as the right answer
– Jignesh Shah
Dec 21 '16 at 12:18
this should be marked as the right answer
– Jignesh Shah
Dec 21 '16 at 12:18
2
2
Any idea on how should we generate the ID?
– Mauker
Jul 25 '17 at 16:34
Any idea on how should we generate the ID?
– Mauker
Jul 25 '17 at 16:34
|
show 7 more comments
According to this issue page ....it is the default recycleview item change animation... You can turn it off.. try this
recyclerView.getItemAnimator().setSupportsChangeAnimations(false);
Change in latest version
Quoted from Android developer blog:
Note that this new API is not backward compatible. If you previously
implemented an ItemAnimator, you can instead extend
SimpleItemAnimator, which provides the old API by wrapping the new
API. You’ll also notice that some methods have been entirely removed
from ItemAnimator. For example, if you were calling
recyclerView.getItemAnimator().setSupportsChangeAnimations(false),
this code won’t compile anymore. You can replace it with:
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
3
@sabeer still same issue. It is not resolving the issue.
– iDroid Explorer
Mar 22 '16 at 3:51
3
@delive let me know if you found any solution to this
– iDroid Explorer
Mar 22 '16 at 3:51
I'm use picasso, its something, not appear blink.
– delive
Mar 22 '16 at 8:05
great its working fine.
– RAHULRSANNIDHI
Aug 17 '16 at 9:21
3
Kotlin: (recyclerView.itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
– Pedro Paulo Amorim
Dec 7 '16 at 15:20
|
show 1 more comment
According to this issue page ....it is the default recycleview item change animation... You can turn it off.. try this
recyclerView.getItemAnimator().setSupportsChangeAnimations(false);
Change in latest version
Quoted from Android developer blog:
Note that this new API is not backward compatible. If you previously
implemented an ItemAnimator, you can instead extend
SimpleItemAnimator, which provides the old API by wrapping the new
API. You’ll also notice that some methods have been entirely removed
from ItemAnimator. For example, if you were calling
recyclerView.getItemAnimator().setSupportsChangeAnimations(false),
this code won’t compile anymore. You can replace it with:
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
3
@sabeer still same issue. It is not resolving the issue.
– iDroid Explorer
Mar 22 '16 at 3:51
3
@delive let me know if you found any solution to this
– iDroid Explorer
Mar 22 '16 at 3:51
I'm use picasso, its something, not appear blink.
– delive
Mar 22 '16 at 8:05
great its working fine.
– RAHULRSANNIDHI
Aug 17 '16 at 9:21
3
Kotlin: (recyclerView.itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
– Pedro Paulo Amorim
Dec 7 '16 at 15:20
|
show 1 more comment
According to this issue page ....it is the default recycleview item change animation... You can turn it off.. try this
recyclerView.getItemAnimator().setSupportsChangeAnimations(false);
Change in latest version
Quoted from Android developer blog:
Note that this new API is not backward compatible. If you previously
implemented an ItemAnimator, you can instead extend
SimpleItemAnimator, which provides the old API by wrapping the new
API. You’ll also notice that some methods have been entirely removed
from ItemAnimator. For example, if you were calling
recyclerView.getItemAnimator().setSupportsChangeAnimations(false),
this code won’t compile anymore. You can replace it with:
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
According to this issue page ....it is the default recycleview item change animation... You can turn it off.. try this
recyclerView.getItemAnimator().setSupportsChangeAnimations(false);
Change in latest version
Quoted from Android developer blog:
Note that this new API is not backward compatible. If you previously
implemented an ItemAnimator, you can instead extend
SimpleItemAnimator, which provides the old API by wrapping the new
API. You’ll also notice that some methods have been entirely removed
from ItemAnimator. For example, if you were calling
recyclerView.getItemAnimator().setSupportsChangeAnimations(false),
this code won’t compile anymore. You can replace it with:
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
edited Oct 21 '16 at 13:04
Sufian
4,83473699
4,83473699
answered Aug 26 '15 at 12:57
Sabeer MohammedSabeer Mohammed
2,7321717
2,7321717
3
@sabeer still same issue. It is not resolving the issue.
– iDroid Explorer
Mar 22 '16 at 3:51
3
@delive let me know if you found any solution to this
– iDroid Explorer
Mar 22 '16 at 3:51
I'm use picasso, its something, not appear blink.
– delive
Mar 22 '16 at 8:05
great its working fine.
– RAHULRSANNIDHI
Aug 17 '16 at 9:21
3
Kotlin: (recyclerView.itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
– Pedro Paulo Amorim
Dec 7 '16 at 15:20
|
show 1 more comment
3
@sabeer still same issue. It is not resolving the issue.
– iDroid Explorer
Mar 22 '16 at 3:51
3
@delive let me know if you found any solution to this
– iDroid Explorer
Mar 22 '16 at 3:51
I'm use picasso, its something, not appear blink.
– delive
Mar 22 '16 at 8:05
great its working fine.
– RAHULRSANNIDHI
Aug 17 '16 at 9:21
3
Kotlin: (recyclerView.itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
– Pedro Paulo Amorim
Dec 7 '16 at 15:20
3
3
@sabeer still same issue. It is not resolving the issue.
– iDroid Explorer
Mar 22 '16 at 3:51
@sabeer still same issue. It is not resolving the issue.
– iDroid Explorer
Mar 22 '16 at 3:51
3
3
@delive let me know if you found any solution to this
– iDroid Explorer
Mar 22 '16 at 3:51
@delive let me know if you found any solution to this
– iDroid Explorer
Mar 22 '16 at 3:51
I'm use picasso, its something, not appear blink.
– delive
Mar 22 '16 at 8:05
I'm use picasso, its something, not appear blink.
– delive
Mar 22 '16 at 8:05
great its working fine.
– RAHULRSANNIDHI
Aug 17 '16 at 9:21
great its working fine.
– RAHULRSANNIDHI
Aug 17 '16 at 9:21
3
3
Kotlin: (recyclerView.itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
– Pedro Paulo Amorim
Dec 7 '16 at 15:20
Kotlin: (recyclerView.itemAnimator as? SimpleItemAnimator)?.supportsChangeAnimations = false
– Pedro Paulo Amorim
Dec 7 '16 at 15:20
|
show 1 more comment
This simply worked:
recyclerView.getItemAnimator().setChangeDuration(0);
1
Worked like a charm! thanks
– Alireza
Jun 29 '16 at 11:36
it's a good alternative tocode
ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); }code
– ziniestro
Sep 14 '16 at 2:40
stops all the animations ADD and REMOVE
– MBH
Aug 4 '17 at 23:23
add a comment |
This simply worked:
recyclerView.getItemAnimator().setChangeDuration(0);
1
Worked like a charm! thanks
– Alireza
Jun 29 '16 at 11:36
it's a good alternative tocode
ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); }code
– ziniestro
Sep 14 '16 at 2:40
stops all the animations ADD and REMOVE
– MBH
Aug 4 '17 at 23:23
add a comment |
This simply worked:
recyclerView.getItemAnimator().setChangeDuration(0);
This simply worked:
recyclerView.getItemAnimator().setChangeDuration(0);
answered Jan 19 '16 at 14:25
Hamzeh SobohHamzeh Soboh
4,47052950
4,47052950
1
Worked like a charm! thanks
– Alireza
Jun 29 '16 at 11:36
it's a good alternative tocode
ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); }code
– ziniestro
Sep 14 '16 at 2:40
stops all the animations ADD and REMOVE
– MBH
Aug 4 '17 at 23:23
add a comment |
1
Worked like a charm! thanks
– Alireza
Jun 29 '16 at 11:36
it's a good alternative tocode
ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); }code
– ziniestro
Sep 14 '16 at 2:40
stops all the animations ADD and REMOVE
– MBH
Aug 4 '17 at 23:23
1
1
Worked like a charm! thanks
– Alireza
Jun 29 '16 at 11:36
Worked like a charm! thanks
– Alireza
Jun 29 '16 at 11:36
it's a good alternative to
code
ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); } code
– ziniestro
Sep 14 '16 at 2:40
it's a good alternative to
code
ItemAnimator animator = recyclerView.getItemAnimator(); if (animator instanceof SimpleItemAnimator) { ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false); } code
– ziniestro
Sep 14 '16 at 2:40
stops all the animations ADD and REMOVE
– MBH
Aug 4 '17 at 23:23
stops all the animations ADD and REMOVE
– MBH
Aug 4 '17 at 23:23
add a comment |
I have the same issue loading image from some urls and then imageView blinks.
Solved by using
notifyItemRangeInserted()
instead of
notifyDataSetChanged()
which avoids to reload those unchanged old datas.
add a comment |
I have the same issue loading image from some urls and then imageView blinks.
Solved by using
notifyItemRangeInserted()
instead of
notifyDataSetChanged()
which avoids to reload those unchanged old datas.
add a comment |
I have the same issue loading image from some urls and then imageView blinks.
Solved by using
notifyItemRangeInserted()
instead of
notifyDataSetChanged()
which avoids to reload those unchanged old datas.
I have the same issue loading image from some urls and then imageView blinks.
Solved by using
notifyItemRangeInserted()
instead of
notifyDataSetChanged()
which avoids to reload those unchanged old datas.
edited Aug 30 '18 at 1:36
answered Sep 17 '16 at 4:37
WeselyWesely
388314
388314
add a comment |
add a comment |
try this to disable the default animation
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
this the new way to disable the animation since android support 23
this old way will work for older version of the support library
recyclerView.getItemAnimator().setSupportsChangeAnimations(false)
add a comment |
try this to disable the default animation
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
this the new way to disable the animation since android support 23
this old way will work for older version of the support library
recyclerView.getItemAnimator().setSupportsChangeAnimations(false)
add a comment |
try this to disable the default animation
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
this the new way to disable the animation since android support 23
this old way will work for older version of the support library
recyclerView.getItemAnimator().setSupportsChangeAnimations(false)
try this to disable the default animation
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}
this the new way to disable the animation since android support 23
this old way will work for older version of the support library
recyclerView.getItemAnimator().setSupportsChangeAnimations(false)
answered Dec 22 '15 at 19:31
Mohamed FaroukMohamed Farouk
12622
12622
add a comment |
add a comment |
Assuming mItems
is the collection that backs your Adapter
, why are you removing everything and re-adding? You are basically telling it that everything has changed, so RecyclerView rebinds all views than I assume the Image library does not handle it properly where it still resets the View even though it is the same image url. Maybe they had some baked in solution for AdapterView so that it works fine in GridView.
Instead of calling notifyDataSetChanged
which will cause re-binding all views, call granular notify events (notify added/removed/moved/updated) so that RecyclerView will rebind only necessary views and nothing will flicker.
3
Or maybe it is just a "bug" in RecyclerView? Obviously if it worked fine for last 6 years with AbsListView and now it doesn't with RecyclerView, means something is not OK with RecyclerView, right? :) Quick look into it shows that when you refresh data in ListView and GridView they keep track of view+position, so when you refresh you will get exactly the same viewholder. While RecyclerView shuffles view holders, which leads in flickering.
– vovkab
May 20 '15 at 17:09
Working on ListView does not mean it is correct for RecyclerView. These components have different architectures.
– yigit
May 20 '15 at 19:27
1
Agree, but sometimes it is really hard to know what items is changed, for example if you use cursors or you just refresh you whole data. So recyclerview should handle this case correctly too.
– vovkab
May 20 '15 at 20:58
add a comment |
Assuming mItems
is the collection that backs your Adapter
, why are you removing everything and re-adding? You are basically telling it that everything has changed, so RecyclerView rebinds all views than I assume the Image library does not handle it properly where it still resets the View even though it is the same image url. Maybe they had some baked in solution for AdapterView so that it works fine in GridView.
Instead of calling notifyDataSetChanged
which will cause re-binding all views, call granular notify events (notify added/removed/moved/updated) so that RecyclerView will rebind only necessary views and nothing will flicker.
3
Or maybe it is just a "bug" in RecyclerView? Obviously if it worked fine for last 6 years with AbsListView and now it doesn't with RecyclerView, means something is not OK with RecyclerView, right? :) Quick look into it shows that when you refresh data in ListView and GridView they keep track of view+position, so when you refresh you will get exactly the same viewholder. While RecyclerView shuffles view holders, which leads in flickering.
– vovkab
May 20 '15 at 17:09
Working on ListView does not mean it is correct for RecyclerView. These components have different architectures.
– yigit
May 20 '15 at 19:27
1
Agree, but sometimes it is really hard to know what items is changed, for example if you use cursors or you just refresh you whole data. So recyclerview should handle this case correctly too.
– vovkab
May 20 '15 at 20:58
add a comment |
Assuming mItems
is the collection that backs your Adapter
, why are you removing everything and re-adding? You are basically telling it that everything has changed, so RecyclerView rebinds all views than I assume the Image library does not handle it properly where it still resets the View even though it is the same image url. Maybe they had some baked in solution for AdapterView so that it works fine in GridView.
Instead of calling notifyDataSetChanged
which will cause re-binding all views, call granular notify events (notify added/removed/moved/updated) so that RecyclerView will rebind only necessary views and nothing will flicker.
Assuming mItems
is the collection that backs your Adapter
, why are you removing everything and re-adding? You are basically telling it that everything has changed, so RecyclerView rebinds all views than I assume the Image library does not handle it properly where it still resets the View even though it is the same image url. Maybe they had some baked in solution for AdapterView so that it works fine in GridView.
Instead of calling notifyDataSetChanged
which will cause re-binding all views, call granular notify events (notify added/removed/moved/updated) so that RecyclerView will rebind only necessary views and nothing will flicker.
edited Mar 30 '15 at 8:35
Ali
4,6331650114
4,6331650114
answered Mar 30 '15 at 4:33
yigityigit
24.4k75753
24.4k75753
3
Or maybe it is just a "bug" in RecyclerView? Obviously if it worked fine for last 6 years with AbsListView and now it doesn't with RecyclerView, means something is not OK with RecyclerView, right? :) Quick look into it shows that when you refresh data in ListView and GridView they keep track of view+position, so when you refresh you will get exactly the same viewholder. While RecyclerView shuffles view holders, which leads in flickering.
– vovkab
May 20 '15 at 17:09
Working on ListView does not mean it is correct for RecyclerView. These components have different architectures.
– yigit
May 20 '15 at 19:27
1
Agree, but sometimes it is really hard to know what items is changed, for example if you use cursors or you just refresh you whole data. So recyclerview should handle this case correctly too.
– vovkab
May 20 '15 at 20:58
add a comment |
3
Or maybe it is just a "bug" in RecyclerView? Obviously if it worked fine for last 6 years with AbsListView and now it doesn't with RecyclerView, means something is not OK with RecyclerView, right? :) Quick look into it shows that when you refresh data in ListView and GridView they keep track of view+position, so when you refresh you will get exactly the same viewholder. While RecyclerView shuffles view holders, which leads in flickering.
– vovkab
May 20 '15 at 17:09
Working on ListView does not mean it is correct for RecyclerView. These components have different architectures.
– yigit
May 20 '15 at 19:27
1
Agree, but sometimes it is really hard to know what items is changed, for example if you use cursors or you just refresh you whole data. So recyclerview should handle this case correctly too.
– vovkab
May 20 '15 at 20:58
3
3
Or maybe it is just a "bug" in RecyclerView? Obviously if it worked fine for last 6 years with AbsListView and now it doesn't with RecyclerView, means something is not OK with RecyclerView, right? :) Quick look into it shows that when you refresh data in ListView and GridView they keep track of view+position, so when you refresh you will get exactly the same viewholder. While RecyclerView shuffles view holders, which leads in flickering.
– vovkab
May 20 '15 at 17:09
Or maybe it is just a "bug" in RecyclerView? Obviously if it worked fine for last 6 years with AbsListView and now it doesn't with RecyclerView, means something is not OK with RecyclerView, right? :) Quick look into it shows that when you refresh data in ListView and GridView they keep track of view+position, so when you refresh you will get exactly the same viewholder. While RecyclerView shuffles view holders, which leads in flickering.
– vovkab
May 20 '15 at 17:09
Working on ListView does not mean it is correct for RecyclerView. These components have different architectures.
– yigit
May 20 '15 at 19:27
Working on ListView does not mean it is correct for RecyclerView. These components have different architectures.
– yigit
May 20 '15 at 19:27
1
1
Agree, but sometimes it is really hard to know what items is changed, for example if you use cursors or you just refresh you whole data. So recyclerview should handle this case correctly too.
– vovkab
May 20 '15 at 20:58
Agree, but sometimes it is really hard to know what items is changed, for example if you use cursors or you just refresh you whole data. So recyclerview should handle this case correctly too.
– vovkab
May 20 '15 at 20:58
add a comment |
Hey @Ali it might be late replay. I also faced this issue and solved with below solution, it may help you please check.
LruBitmapCache.java class is created to get image cache size
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements
ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
public LruBitmapCache() {
this(getDefaultLruCacheSize());
}
public LruBitmapCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
}
VolleyClient.java singleton class [extends Application] added below code
in VolleyClient singleton class constructor add below snippet to initialize the ImageLoader
private VolleyClient(Context context)
{
mCtx = context;
mRequestQueue = getRequestQueue();
mImageLoader = new ImageLoader(mRequestQueue,getLruBitmapCache());
}
I created getLruBitmapCache() method to return LruBitmapCache
public LruBitmapCache getLruBitmapCache() {
if (mLruBitmapCache == null)
mLruBitmapCache = new LruBitmapCache();
return this.mLruBitmapCache;
}
Hope its going to help you.
Thanks for your answer. That's what I have exactly done in my VollyClient.java. Take a look at :VolleyClient.java
– Ali
Jun 20 '15 at 12:25
Just check once with using LruCache<String, Bitmap> class, I think its going to solve your problem. Take a look at LruCache
– Android learner
Jun 20 '15 at 14:55
Did you check once the code that I shared with you in comment? what do you have in your class that I missed there?
– Ali
Jun 20 '15 at 15:04
You are missing extending LruCache<String, Bitmap> class and overriding sizeOf() method like how I done, remaining all are seems okay to me.
– Android learner
Jun 20 '15 at 15:11
Ok, I give it a try very soon, but could you explain me what have you done there which did the magic for you and solve the problem? sourcecode For me it sounds like your overriden sizeOf method should be in the source code.
– Ali
Jun 20 '15 at 16:48
|
show 4 more comments
Hey @Ali it might be late replay. I also faced this issue and solved with below solution, it may help you please check.
LruBitmapCache.java class is created to get image cache size
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements
ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
public LruBitmapCache() {
this(getDefaultLruCacheSize());
}
public LruBitmapCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
}
VolleyClient.java singleton class [extends Application] added below code
in VolleyClient singleton class constructor add below snippet to initialize the ImageLoader
private VolleyClient(Context context)
{
mCtx = context;
mRequestQueue = getRequestQueue();
mImageLoader = new ImageLoader(mRequestQueue,getLruBitmapCache());
}
I created getLruBitmapCache() method to return LruBitmapCache
public LruBitmapCache getLruBitmapCache() {
if (mLruBitmapCache == null)
mLruBitmapCache = new LruBitmapCache();
return this.mLruBitmapCache;
}
Hope its going to help you.
Thanks for your answer. That's what I have exactly done in my VollyClient.java. Take a look at :VolleyClient.java
– Ali
Jun 20 '15 at 12:25
Just check once with using LruCache<String, Bitmap> class, I think its going to solve your problem. Take a look at LruCache
– Android learner
Jun 20 '15 at 14:55
Did you check once the code that I shared with you in comment? what do you have in your class that I missed there?
– Ali
Jun 20 '15 at 15:04
You are missing extending LruCache<String, Bitmap> class and overriding sizeOf() method like how I done, remaining all are seems okay to me.
– Android learner
Jun 20 '15 at 15:11
Ok, I give it a try very soon, but could you explain me what have you done there which did the magic for you and solve the problem? sourcecode For me it sounds like your overriden sizeOf method should be in the source code.
– Ali
Jun 20 '15 at 16:48
|
show 4 more comments
Hey @Ali it might be late replay. I also faced this issue and solved with below solution, it may help you please check.
LruBitmapCache.java class is created to get image cache size
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements
ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
public LruBitmapCache() {
this(getDefaultLruCacheSize());
}
public LruBitmapCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
}
VolleyClient.java singleton class [extends Application] added below code
in VolleyClient singleton class constructor add below snippet to initialize the ImageLoader
private VolleyClient(Context context)
{
mCtx = context;
mRequestQueue = getRequestQueue();
mImageLoader = new ImageLoader(mRequestQueue,getLruBitmapCache());
}
I created getLruBitmapCache() method to return LruBitmapCache
public LruBitmapCache getLruBitmapCache() {
if (mLruBitmapCache == null)
mLruBitmapCache = new LruBitmapCache();
return this.mLruBitmapCache;
}
Hope its going to help you.
Hey @Ali it might be late replay. I also faced this issue and solved with below solution, it may help you please check.
LruBitmapCache.java class is created to get image cache size
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class LruBitmapCache extends LruCache<String, Bitmap> implements
ImageCache {
public static int getDefaultLruCacheSize() {
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
public LruBitmapCache() {
this(getDefaultLruCacheSize());
}
public LruBitmapCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
}
VolleyClient.java singleton class [extends Application] added below code
in VolleyClient singleton class constructor add below snippet to initialize the ImageLoader
private VolleyClient(Context context)
{
mCtx = context;
mRequestQueue = getRequestQueue();
mImageLoader = new ImageLoader(mRequestQueue,getLruBitmapCache());
}
I created getLruBitmapCache() method to return LruBitmapCache
public LruBitmapCache getLruBitmapCache() {
if (mLruBitmapCache == null)
mLruBitmapCache = new LruBitmapCache();
return this.mLruBitmapCache;
}
Hope its going to help you.
edited Jun 20 '15 at 12:20
answered Jun 20 '15 at 12:10
Android learnerAndroid learner
86841834
86841834
Thanks for your answer. That's what I have exactly done in my VollyClient.java. Take a look at :VolleyClient.java
– Ali
Jun 20 '15 at 12:25
Just check once with using LruCache<String, Bitmap> class, I think its going to solve your problem. Take a look at LruCache
– Android learner
Jun 20 '15 at 14:55
Did you check once the code that I shared with you in comment? what do you have in your class that I missed there?
– Ali
Jun 20 '15 at 15:04
You are missing extending LruCache<String, Bitmap> class and overriding sizeOf() method like how I done, remaining all are seems okay to me.
– Android learner
Jun 20 '15 at 15:11
Ok, I give it a try very soon, but could you explain me what have you done there which did the magic for you and solve the problem? sourcecode For me it sounds like your overriden sizeOf method should be in the source code.
– Ali
Jun 20 '15 at 16:48
|
show 4 more comments
Thanks for your answer. That's what I have exactly done in my VollyClient.java. Take a look at :VolleyClient.java
– Ali
Jun 20 '15 at 12:25
Just check once with using LruCache<String, Bitmap> class, I think its going to solve your problem. Take a look at LruCache
– Android learner
Jun 20 '15 at 14:55
Did you check once the code that I shared with you in comment? what do you have in your class that I missed there?
– Ali
Jun 20 '15 at 15:04
You are missing extending LruCache<String, Bitmap> class and overriding sizeOf() method like how I done, remaining all are seems okay to me.
– Android learner
Jun 20 '15 at 15:11
Ok, I give it a try very soon, but could you explain me what have you done there which did the magic for you and solve the problem? sourcecode For me it sounds like your overriden sizeOf method should be in the source code.
– Ali
Jun 20 '15 at 16:48
Thanks for your answer. That's what I have exactly done in my VollyClient.java. Take a look at :VolleyClient.java
– Ali
Jun 20 '15 at 12:25
Thanks for your answer. That's what I have exactly done in my VollyClient.java. Take a look at :VolleyClient.java
– Ali
Jun 20 '15 at 12:25
Just check once with using LruCache<String, Bitmap> class, I think its going to solve your problem. Take a look at LruCache
– Android learner
Jun 20 '15 at 14:55
Just check once with using LruCache<String, Bitmap> class, I think its going to solve your problem. Take a look at LruCache
– Android learner
Jun 20 '15 at 14:55
Did you check once the code that I shared with you in comment? what do you have in your class that I missed there?
– Ali
Jun 20 '15 at 15:04
Did you check once the code that I shared with you in comment? what do you have in your class that I missed there?
– Ali
Jun 20 '15 at 15:04
You are missing extending LruCache<String, Bitmap> class and overriding sizeOf() method like how I done, remaining all are seems okay to me.
– Android learner
Jun 20 '15 at 15:11
You are missing extending LruCache<String, Bitmap> class and overriding sizeOf() method like how I done, remaining all are seems okay to me.
– Android learner
Jun 20 '15 at 15:11
Ok, I give it a try very soon, but could you explain me what have you done there which did the magic for you and solve the problem? sourcecode For me it sounds like your overriden sizeOf method should be in the source code.
– Ali
Jun 20 '15 at 16:48
Ok, I give it a try very soon, but could you explain me what have you done there which did the magic for you and solve the problem? sourcecode For me it sounds like your overriden sizeOf method should be in the source code.
– Ali
Jun 20 '15 at 16:48
|
show 4 more comments
Recyclerview uses DefaultItemAnimator as it's default animator.
As you can see from the code below, they change the alpha of the view holder upon item change:
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
...
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
...
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
....
ViewCompat.setAlpha(newHolder.itemView, 0);
}
...
return true;
}
I wanted to retain the rest of the animations but remove the "flicker" so I cloned DefaultItemAnimator and removed the 3 alpha lines above.
To use the new animator just call setItemAnimator() on your RecyclerView:
mRecyclerView.setItemAnimator(new MyItemAnimator());
add a comment |
Recyclerview uses DefaultItemAnimator as it's default animator.
As you can see from the code below, they change the alpha of the view holder upon item change:
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
...
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
...
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
....
ViewCompat.setAlpha(newHolder.itemView, 0);
}
...
return true;
}
I wanted to retain the rest of the animations but remove the "flicker" so I cloned DefaultItemAnimator and removed the 3 alpha lines above.
To use the new animator just call setItemAnimator() on your RecyclerView:
mRecyclerView.setItemAnimator(new MyItemAnimator());
add a comment |
Recyclerview uses DefaultItemAnimator as it's default animator.
As you can see from the code below, they change the alpha of the view holder upon item change:
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
...
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
...
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
....
ViewCompat.setAlpha(newHolder.itemView, 0);
}
...
return true;
}
I wanted to retain the rest of the animations but remove the "flicker" so I cloned DefaultItemAnimator and removed the 3 alpha lines above.
To use the new animator just call setItemAnimator() on your RecyclerView:
mRecyclerView.setItemAnimator(new MyItemAnimator());
Recyclerview uses DefaultItemAnimator as it's default animator.
As you can see from the code below, they change the alpha of the view holder upon item change:
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
...
final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
...
ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
if (newHolder != null) {
....
ViewCompat.setAlpha(newHolder.itemView, 0);
}
...
return true;
}
I wanted to retain the rest of the animations but remove the "flicker" so I cloned DefaultItemAnimator and removed the 3 alpha lines above.
To use the new animator just call setItemAnimator() on your RecyclerView:
mRecyclerView.setItemAnimator(new MyItemAnimator());
answered Jun 29 '16 at 0:19
Peter FilePeter File
451515
451515
add a comment |
add a comment |
I had similar issue and this worked for me
You can call this method to set size for image cache
private int getCacheSize(Context context) {
final DisplayMetrics displayMetrics = context.getResources().
getDisplayMetrics();
final int screenWidth = displayMetrics.widthPixels;
final int screenHeight = displayMetrics.heightPixels;
// 4 bytes per pixel
final int screenBytes = screenWidth * screenHeight * 4;
return screenBytes * 3;
}
add a comment |
I had similar issue and this worked for me
You can call this method to set size for image cache
private int getCacheSize(Context context) {
final DisplayMetrics displayMetrics = context.getResources().
getDisplayMetrics();
final int screenWidth = displayMetrics.widthPixels;
final int screenHeight = displayMetrics.heightPixels;
// 4 bytes per pixel
final int screenBytes = screenWidth * screenHeight * 4;
return screenBytes * 3;
}
add a comment |
I had similar issue and this worked for me
You can call this method to set size for image cache
private int getCacheSize(Context context) {
final DisplayMetrics displayMetrics = context.getResources().
getDisplayMetrics();
final int screenWidth = displayMetrics.widthPixels;
final int screenHeight = displayMetrics.heightPixels;
// 4 bytes per pixel
final int screenBytes = screenWidth * screenHeight * 4;
return screenBytes * 3;
}
I had similar issue and this worked for me
You can call this method to set size for image cache
private int getCacheSize(Context context) {
final DisplayMetrics displayMetrics = context.getResources().
getDisplayMetrics();
final int screenWidth = displayMetrics.widthPixels;
final int screenHeight = displayMetrics.heightPixels;
// 4 bytes per pixel
final int screenBytes = screenWidth * screenHeight * 4;
return screenBytes * 3;
}
edited Aug 13 '15 at 10:30
ketan
15k123463
15k123463
answered Aug 13 '15 at 10:25
developer_androiddeveloper_android
11
11
add a comment |
add a comment |
for my application, I had some data changing but I didn't want the entire view to blink.
I solved it by only fading the oldview down 0.5 alpha and starting the newview alpha at 0.5. This created a softer fading transition without making the view disappear completely.
Unfortunately because of private implementations, I couldn't subclass the DefaultItemAnimator in order to make this change so I had to clone the code and make the following changes
in animateChange:
ViewCompat.setAlpha(newHolder.itemView, 0); //change 0 to 0.5f
in animateChangeImpl:
oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() { //change 0 to 0.5f
add a comment |
for my application, I had some data changing but I didn't want the entire view to blink.
I solved it by only fading the oldview down 0.5 alpha and starting the newview alpha at 0.5. This created a softer fading transition without making the view disappear completely.
Unfortunately because of private implementations, I couldn't subclass the DefaultItemAnimator in order to make this change so I had to clone the code and make the following changes
in animateChange:
ViewCompat.setAlpha(newHolder.itemView, 0); //change 0 to 0.5f
in animateChangeImpl:
oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() { //change 0 to 0.5f
add a comment |
for my application, I had some data changing but I didn't want the entire view to blink.
I solved it by only fading the oldview down 0.5 alpha and starting the newview alpha at 0.5. This created a softer fading transition without making the view disappear completely.
Unfortunately because of private implementations, I couldn't subclass the DefaultItemAnimator in order to make this change so I had to clone the code and make the following changes
in animateChange:
ViewCompat.setAlpha(newHolder.itemView, 0); //change 0 to 0.5f
in animateChangeImpl:
oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() { //change 0 to 0.5f
for my application, I had some data changing but I didn't want the entire view to blink.
I solved it by only fading the oldview down 0.5 alpha and starting the newview alpha at 0.5. This created a softer fading transition without making the view disappear completely.
Unfortunately because of private implementations, I couldn't subclass the DefaultItemAnimator in order to make this change so I had to clone the code and make the following changes
in animateChange:
ViewCompat.setAlpha(newHolder.itemView, 0); //change 0 to 0.5f
in animateChangeImpl:
oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() { //change 0 to 0.5f
edited Apr 25 '16 at 19:24
tinlyx
10.8k1956109
10.8k1956109
answered Apr 25 '16 at 19:06
DeeferDeefer
314
314
add a comment |
add a comment |
for me recyclerView.setHasFixedSize(true);
worked
add a comment |
for me recyclerView.setHasFixedSize(true);
worked
add a comment |
for me recyclerView.setHasFixedSize(true);
worked
for me recyclerView.setHasFixedSize(true);
worked
answered Jun 22 '16 at 13:59
PramodPramod
86321128
86321128
add a comment |
add a comment |
Using appropriate recyclerview methods to update views will solve this issue
First, make changes in the list
mList.add(item);
or mList.addAll(itemList);
or mList.remove(index);
Then notify using
notifyItemInserted(addedItemIndex);
or
notifyItemRemoved(removedItemIndex);
or
notifyItemRangeChanged(fromIndex, newUpdatedItemCount);
Hope this will help!!
Absolutely not. If you are making several updates by seconds (BLE scanning in my case) it doesn't work at all. I spent one day to update to this shit RecyclerAdapter... Better to keep ArrayAdapter. It's a shame that's not using MVC pattern, but at least it's almost usable.
– Gojir4
Jun 4 '18 at 15:01
add a comment |
Using appropriate recyclerview methods to update views will solve this issue
First, make changes in the list
mList.add(item);
or mList.addAll(itemList);
or mList.remove(index);
Then notify using
notifyItemInserted(addedItemIndex);
or
notifyItemRemoved(removedItemIndex);
or
notifyItemRangeChanged(fromIndex, newUpdatedItemCount);
Hope this will help!!
Absolutely not. If you are making several updates by seconds (BLE scanning in my case) it doesn't work at all. I spent one day to update to this shit RecyclerAdapter... Better to keep ArrayAdapter. It's a shame that's not using MVC pattern, but at least it's almost usable.
– Gojir4
Jun 4 '18 at 15:01
add a comment |
Using appropriate recyclerview methods to update views will solve this issue
First, make changes in the list
mList.add(item);
or mList.addAll(itemList);
or mList.remove(index);
Then notify using
notifyItemInserted(addedItemIndex);
or
notifyItemRemoved(removedItemIndex);
or
notifyItemRangeChanged(fromIndex, newUpdatedItemCount);
Hope this will help!!
Using appropriate recyclerview methods to update views will solve this issue
First, make changes in the list
mList.add(item);
or mList.addAll(itemList);
or mList.remove(index);
Then notify using
notifyItemInserted(addedItemIndex);
or
notifyItemRemoved(removedItemIndex);
or
notifyItemRangeChanged(fromIndex, newUpdatedItemCount);
Hope this will help!!
edited Apr 14 '17 at 11:47
answered Aug 24 '16 at 9:16
Sreedhu MadhuSreedhu Madhu
1,40521432
1,40521432
Absolutely not. If you are making several updates by seconds (BLE scanning in my case) it doesn't work at all. I spent one day to update to this shit RecyclerAdapter... Better to keep ArrayAdapter. It's a shame that's not using MVC pattern, but at least it's almost usable.
– Gojir4
Jun 4 '18 at 15:01
add a comment |
Absolutely not. If you are making several updates by seconds (BLE scanning in my case) it doesn't work at all. I spent one day to update to this shit RecyclerAdapter... Better to keep ArrayAdapter. It's a shame that's not using MVC pattern, but at least it's almost usable.
– Gojir4
Jun 4 '18 at 15:01
Absolutely not. If you are making several updates by seconds (BLE scanning in my case) it doesn't work at all. I spent one day to update to this shit RecyclerAdapter... Better to keep ArrayAdapter. It's a shame that's not using MVC pattern, but at least it's almost usable.
– Gojir4
Jun 4 '18 at 15:01
Absolutely not. If you are making several updates by seconds (BLE scanning in my case) it doesn't work at all. I spent one day to update to this shit RecyclerAdapter... Better to keep ArrayAdapter. It's a shame that's not using MVC pattern, but at least it's almost usable.
– Gojir4
Jun 4 '18 at 15:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f29331075%2frecyclerview-blinking-after-notifydatasetchanged%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Possible duplicate of Disable onChange animations on ItemAnimator for RecyclerView
– Apfelsaft23
Nov 24 '18 at 15:06